From 04ffe03f4bf1a98469dca152bcbc250bd0860111 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 30 May 2017 18:39:15 +0200 Subject: [PATCH] [FIX] sale: default company on SO In multi-company: - Create 2 companies A and B - Set the superuser on company B - Set the website on company A - Define company specific sequences for SO (e.g. SOA and SOB) When a SO is generated from the eCommerce, it is defined on company A (thanks to 8a1b55a), but the sequence is from company B. opw-744561 --- addons/sale/sale.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index d8a3bee8cfa..802457694f2 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -225,7 +225,10 @@ class SaleOrder(models.Model): @api.model def create(self, vals): if vals.get('name', _('New')) == _('New'): - vals['name'] = self.env['ir.sequence'].next_by_code('sale.order') or _('New') + if 'company_id' in vals: + vals['name'] = self.env['ir.sequence'].with_context(force_company=vals['company_id']).next_by_code('sale.order') or _('New') + else: + vals['name'] = self.env['ir.sequence'].next_by_code('sale.order') or _('New') # Makes sure partner_invoice_id', 'partner_shipping_id' and 'pricelist_id' are defined if any(f not in vals for f in ['partner_invoice_id', 'partner_shipping_id', 'pricelist_id']):