From 2bffd654518a72ecc4c9df07f9565e4789f4b195 Mon Sep 17 00:00:00 2001 From: rhe Date: Fri, 17 May 2019 13:19:26 +0000 Subject: [PATCH] [IMP] point_of_sale: improve multi company Since the company is not stored anymore on the user and is in the environement, some parts of the code that was based on the current user company cannot work anymore. We've adapted the code to take the company from the relevent documents to avoid having inconsistencies through the different documents generated in the point of sale. TASK-ID: 1997613 closes odoo/odoo#33556 Signed-off-by: pimodoo --- addons/point_of_sale/models/pos_order.py | 10 +++-- addons/point_of_sale/models/pos_session.py | 2 + addons/point_of_sale/static/src/js/models.js | 6 +-- .../point_of_sale/views/pos_config_view.xml | 43 ++++++++++--------- .../point_of_sale/views/pos_session_view.xml | 8 ++-- addons/pos_hr/static/src/js/models.js | 4 +- addons/pos_hr/views/pos_config.xml | 4 +- addons/pos_sale/models/pos_config.py | 9 ++-- addons/pos_sale/views/pos_config_views.xml | 4 +- addons/stock/models/stock_picking.py | 1 + 10 files changed, 49 insertions(+), 42 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 2765edfb8e1..c7e4f140dc2 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -536,8 +536,10 @@ class PosOrder(models.Model): def _default_pricelist(self): return self._default_session().config_id.pricelist_id + def _default_company_id(self): + return self._default_session().config_id.company_id + name = fields.Char(string='Order Ref', required=True, readonly=True, copy=False, default='/') - company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) date_order = fields.Datetime(string='Order Date', readonly=True, index=True, default=fields.Datetime.now) user_id = fields.Many2one( comodel_name='res.users', string='User', @@ -552,6 +554,8 @@ class PosOrder(models.Model): amount_return = fields.Float(string='Returned', digits=0, required=True, readonly=True) lines = fields.One2many('pos.order.line', 'order_id', string='Order Lines', states={'draft': [('readonly', False)]}, readonly=True, copy=True) statement_ids = fields.One2many('account.bank.statement.line', 'pos_statement_id', string='Payments', states={'draft': [('readonly', False)]}, readonly=True) + company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, + default=lambda self: self._default_company_id()) pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', required=True, states={ 'draft': [('readonly', False)]}, readonly=True, default=_default_pricelist) partner_id = fields.Many2one('res.partner', string='Customer', change_default=True, index=True, states={'draft': [('readonly', False)], 'paid': [('readonly', False)]}) @@ -1048,7 +1052,7 @@ class PosOrderLine(models.Model): line[2]['tax_ids'] = [(6, 0, [x.id for x in product.taxes_id])] return line - company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company) + company_id = fields.Many2one('res.company', string='Company', related="order_id.company_id", store=True) name = fields.Char(string='Line No', required=True, copy=False) notice = fields.Char(string='Discount Notice') product_id = fields.Many2one('product.product', string='Product', domain=[('sale_ok', '=', True)], required=True, change_default=True) @@ -1059,7 +1063,7 @@ class PosOrderLine(models.Model): price_subtotal_incl = fields.Float(string='Subtotal', digits=0, readonly=True, required=True) discount = fields.Float(string='Discount (%)', digits=0, default=0.0) - order_id = fields.Many2one('pos.order', string='Order Ref', ondelete='cascade') + order_id = fields.Many2one('pos.order', string='Order Ref', ondelete='cascade', required=True) tax_ids = fields.Many2many('account.tax', string='Taxes', readonly=True) tax_ids_after_fiscal_position = fields.Many2many('account.tax', compute='_get_tax_ids_after_fiscal_position', string='Taxes to Apply') pack_lot_ids = fields.One2many('pos.pack.operation.lot', 'pos_order_line_id', string='Lot/serial Number') diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index a71905409e0..a101a6da380 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -40,6 +40,8 @@ class PosSession(models.Model): orders_to_reconcile = session.order_ids._filtered_for_reconciliation() orders_to_reconcile.sudo()._reconcile_payments() + company_id = fields.Many2one('res.company', related='config_id.company_id', string="Company", readonly=True) + config_id = fields.Many2one( 'pos.config', string='Point of Sale', help="The physical point of sale you will use.", diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 5cf80e1e64d..a594820e031 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -263,10 +263,6 @@ exports.PosModel = Backbone.Model.extend({ self.config.iface_cashdrawer || self.config.iface_customer_facing_display; - if (self.config.company_id[0] !== self.user.company_id[0]) { - throw new Error(_t("Error: The Point of Sale User must belong to the same company as the Point of Sale. You are probably trying to load the point of sale as an administrator in a multi-company setup, with the administrator account set to the wrong company.")); - } - self.db.set_uuid(self.config.uuid); self.set_cashier(self.get_cashier()); // We need to do it here, since only then the local storage has the correct uuid @@ -345,7 +341,7 @@ exports.PosModel = Backbone.Model.extend({ 'product_tmpl_id','tracking'], order: _.map(['sequence','default_code','name'], function (name) { return {name: name}; }), domain: function(self){ - var domain = [['sale_ok','=',true],['available_in_pos','=',true]]; + var domain = [['sale_ok','=',true],['available_in_pos','=',true],'|',['company_id','=',self.config.company_id[0]],['company_id','=',false]]; if (self.config.limit_categories && self.config.iface_available_categ_ids.length) { domain.push(['pos_categ_id', 'in', self.config.iface_available_categ_ids]); } diff --git a/addons/point_of_sale/views/pos_config_view.xml b/addons/point_of_sale/views/pos_config_view.xml index 8ccac51c746..cd812498780 100644 --- a/addons/point_of_sale/views/pos_config_view.xml +++ b/addons/point_of_sale/views/pos_config_view.xml @@ -45,7 +45,7 @@
@@ -211,7 +211,7 @@
- +
- +
- +
@@ -247,19 +247,19 @@

Pricing

-
-
-
@@ -289,7 +289,7 @@
@@ -461,7 +463,7 @@ Products will be taken from the default source location of this operation type
- +
@@ -477,7 +479,7 @@
diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 5c48553d49c..8b62d829ce1 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -64,6 +64,7 @@ class PickingType(models.Model): rate_picking_late = fields.Integer(compute='_compute_picking_count') rate_picking_backorders = fields.Integer(compute='_compute_picking_count') barcode = fields.Char('Barcode', copy=False) + company_id = fields.Many2one('res.company', 'Company', related='warehouse_id.company_id', store=True) @api.one def _compute_last_done_picking(self):