diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 2b614f7cd6e..1391e5f0409 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -37,7 +37,7 @@ class AccountMove(models.Model): return # Copy data from PO - invoice_vals = self.purchase_id._prepare_invoice() + invoice_vals = self.purchase_id.with_company(self.purchase_id.company_id)._prepare_invoice() self.update(invoice_vals) # Copy purchase lines. diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index f6d5b97fbbf..bbc37b9c546 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -461,6 +461,7 @@ class PurchaseOrder(models.Model): if order.invoice_status != 'to invoice': continue + order = order.with_company(order.company_id) pending_section = None # Invoice values. invoice_vals = order._prepare_invoice() @@ -519,7 +520,6 @@ class PurchaseOrder(models.Model): """Prepare the dict of values to create the new invoice for a purchase order. """ self.ensure_one() - self = self.with_company(self.company_id) move_type = self._context.get('default_move_type', 'in_invoice') journal = self.env['account.move'].with_context(default_move_type=move_type)._get_default_journal() if not journal: diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 2815aa92761..8c90b4d5047 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -533,8 +533,7 @@ class SaleOrder(models.Model): a clean extension chain). """ self.ensure_one() - self = self.with_company(self.company_id) - journal = self.env['account.move'].with_company(self.company_id).with_context(default_move_type='out_invoice')._get_default_journal() + journal = self.env['account.move'].with_context(default_move_type='out_invoice')._get_default_journal() if not journal: raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % (self.company_id.name, self.company_id.id)) @@ -631,8 +630,9 @@ Reason(s) of this behavior could be: invoice_vals_list = [] invoice_item_sequence = 0 for order in self: + order = order.with_company(order.company_id) current_section_vals = None - down_payments = self.env['sale.order.line'] + down_payments = order.env['sale.order.line'] # Invoice values. invoice_vals = order._prepare_invoice() @@ -660,7 +660,7 @@ Reason(s) of this behavior could be: # If down payments are present in SO, group them under common section if down_payments: invoice_item_sequence += 1 - down_payments_section = self._prepare_down_payment_section_line(sequence=invoice_item_sequence) + down_payments_section = order._prepare_down_payment_section_line(sequence=invoice_item_sequence) invoice_lines_vals.append(down_payments_section) for down_payment in down_payments: invoice_item_sequence += 1 diff --git a/addons/sale_purchase/models/sale_order.py b/addons/sale_purchase/models/sale_order.py index 84f5dc89124..a9d6ae19abf 100644 --- a/addons/sale_purchase/models/sale_order.py +++ b/addons/sale_purchase/models/sale_order.py @@ -192,7 +192,6 @@ class SaleOrderLine(models.Model): :rtype: dict """ self.ensure_one() - self = self.with_company(self.company_id) partner_supplier = supplierinfo.name fpos = self.env['account.fiscal.position'].sudo().get_fiscal_position(partner_supplier.id) date_order = self._purchase_get_date_order(supplierinfo)