[IMP] point_of_sale: create one picking type by warehouse

When you are selling goods through point of sale, pinkings are created
to remove what have been sold from the stock. This picking is created by
using the picking_type set on pos_config.

For now, the there is only one picking type POS Order existing by
default, which is located on the first warehouse in data. It means that
if you create another warehouse and/or company, you will have to
manually create picking type if you want to be able to link pos config
to the new warehouse.

So now, each warehouse will have its own picking_type for POS, which
will ease the link between the pos config and the warehouse.

We've also set a default value on pos config to take the first picking
type, and added a domain that will show only the outgoing types.

TASK-ID: 1970513
This commit is contained in:
Pierre Masereel
2019-06-03 09:01:21 +00:00
parent 1f519be1f0
commit a681631dd0
5 changed files with 59 additions and 22 deletions
@@ -1,23 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="seq_picking_type_posout" model="ir.sequence">
<field name="name">Picking POS</field>
<field name="prefix">POS</field>
<field name="padding">5</field>
<field name="company_id" eval="False"/>
</record>
</data>
<data noupdate="0">
<record id="picking_type_posout" model="stock.picking.type">
<field name="name">PoS Orders</field>
<field name="sequence_id" ref="seq_picking_type_posout"/>
<field name="default_location_src_id" ref="stock.stock_location_stock"/>
<field name="default_location_dest_id" ref="stock.stock_location_customers"/>
<field name="warehouse_id" eval="False"/>
<field name="code">outgoing</field>
</record>
</data>
<data noupdate="1">
<!-- After closing the PoS, open the dashboard menu -->
<record id="action_client_pos_menu" model="ir.actions.client">
@@ -26,6 +8,8 @@
<field name="params" eval="{'menu_id': ref('menu_point_root')}"/>
</record>
<function model="stock.warehouse" name="_create_missing_pos_picking_types"/>
<record id="product_category_pos" model="product.category">
<field name="parent_id" ref="product.product_category_1"/>
<field name="name">PoS</field>
@@ -41,7 +25,6 @@
<record model="pos.config" id="pos_config_main">
<field name="name">Shop</field>
<field name="picking_type_id" ref="picking_type_posout"/>
<field name="barcode_nomenclature_id" ref="barcodes.default_barcode_nomenclature"/>
</record>
@@ -72,4 +55,3 @@
</record>
</data>
</odoo>
+1
View File
@@ -14,3 +14,4 @@ from . import product
from . import res_partner
from . import res_company
from . import res_config_settings
from . import stock_warehouse
+8 -1
View File
@@ -39,6 +39,9 @@ class PosConfig(models.Model):
_name = 'pos.config'
_description = 'Point of Sale Configuration'
def _default_picking_type_id(self):
return self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).pos_type_id.id
def _default_sale_journal(self):
journal = self.env.ref('point_of_sale.pos_sale_journal', raise_if_not_found=False)
if journal and journal.sudo().company_id == self.env.company:
@@ -70,7 +73,11 @@ class PosConfig(models.Model):
'account.journal', 'pos_config_journal_rel',
'pos_config_id', 'journal_id', string='Available Payment Methods',
domain="[('journal_user', '=', True ), ('type', 'in', ['bank', 'cash'])]",)
picking_type_id = fields.Many2one('stock.picking.type', string='Operation Type')
picking_type_id = fields.Many2one(
'stock.picking.type',
string='Operation Type',
default=_default_picking_type_id,
domain="[('code', '=', 'outgoing'), ('warehouse_id.company_id', '=', company_id)]")
use_existing_lots = fields.Boolean(related='picking_type_id.use_existing_lots', readonly=False)
stock_location_id = fields.Many2one(
'stock.location', string='Stock Location',
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class Warehouse(models.Model):
_inherit = "stock.warehouse"
pos_type_id = fields.Many2one('stock.picking.type', string="Point of Sale Operation Type")
def _get_sequence_values(self):
sequence_values = super(Warehouse, self)._get_sequence_values()
sequence_values.update({
'pos_type_id': {
'name': self.name + ' ' + _('Picking POS'),
'prefix': self.code + '/POS/',
'padding': 5,
'company_id': self.company_id.id,
}
})
return sequence_values
def _get_picking_type_update_values(self):
picking_type_update_values = super(Warehouse, self)._get_picking_type_update_values()
picking_type_update_values.update({
'pos_type_id': {'default_location_src_id': self.lot_stock_id.id}
})
return picking_type_update_values
def _get_picking_type_create_values(self, max_sequence):
picking_type_create_values, max_sequence = super(Warehouse, self)._get_picking_type_create_values(max_sequence)
picking_type_create_values.update({
'pos_type_id': {
'name': _('PoS Orders'),
'code': 'outgoing',
'default_location_src_id': self.lot_stock_id.id,
'default_location_dest_id': self.env.ref('stock.stock_location_customers').id,
'sequence': max_sequence + 1,
}
})
return picking_type_create_values, max_sequence + 2
@api.model
def _create_missing_pos_picking_types(self):
warehouses = self.env['stock.warehouse'].search([('pos_type_id', '=', False)])
for warehouse in warehouses:
new_vals = warehouse._create_or_update_sequences_and_picking_types()
warehouse.write(new_vals)
@@ -195,7 +195,6 @@
<!-- Pos Config -->
<record model="pos.config" id="pos_config_restaurant">
<field name="name">Bar</field>
<field name="picking_type_id" ref="point_of_sale.picking_type_posout"/>
<field name="barcode_nomenclature_id" ref="barcodes.default_barcode_nomenclature"/>
<field name="module_pos_restaurant">True</field>
<field name="is_table_management">True</field>