From a681631dd094cb261161ff4aa89686969ba5bb37 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Tue, 28 May 2019 12:46:55 +0000 Subject: [PATCH] [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 --- .../point_of_sale/data/point_of_sale_data.xml | 22 +-------- addons/point_of_sale/models/__init__.py | 1 + addons/point_of_sale/models/pos_config.py | 9 +++- .../point_of_sale/models/stock_warehouse.py | 48 +++++++++++++++++++ .../data/pos_restaurant_demo.xml | 1 - 5 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 addons/point_of_sale/models/stock_warehouse.py diff --git a/addons/point_of_sale/data/point_of_sale_data.xml b/addons/point_of_sale/data/point_of_sale_data.xml index 810925e61e3..a1dc7f0e071 100644 --- a/addons/point_of_sale/data/point_of_sale_data.xml +++ b/addons/point_of_sale/data/point_of_sale_data.xml @@ -1,23 +1,5 @@ - - - Picking POS - POS - 5 - - - - - - PoS Orders - - - - - outgoing - - @@ -26,6 +8,8 @@ + + PoS @@ -41,7 +25,6 @@ Shop - @@ -72,4 +55,3 @@ - diff --git a/addons/point_of_sale/models/__init__.py b/addons/point_of_sale/models/__init__.py index 9023c405f2c..70d1073b2e5 100644 --- a/addons/point_of_sale/models/__init__.py +++ b/addons/point_of_sale/models/__init__.py @@ -14,3 +14,4 @@ from . import product from . import res_partner from . import res_company from . import res_config_settings +from . import stock_warehouse diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 7f634f6cd61..34040fff1c4 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -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', diff --git a/addons/point_of_sale/models/stock_warehouse.py b/addons/point_of_sale/models/stock_warehouse.py new file mode 100644 index 00000000000..c4ba29203eb --- /dev/null +++ b/addons/point_of_sale/models/stock_warehouse.py @@ -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) diff --git a/addons/pos_restaurant/data/pos_restaurant_demo.xml b/addons/pos_restaurant/data/pos_restaurant_demo.xml index 1964f5f3d19..4f71aa2c841 100644 --- a/addons/pos_restaurant/data/pos_restaurant_demo.xml +++ b/addons/pos_restaurant/data/pos_restaurant_demo.xml @@ -195,7 +195,6 @@ Bar - True True