summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2020-07-24 10:02:14 +0000
committerVictor Feyens <vfe@odoo.com>2020-07-30 10:20:31 +0000
commitcc665d51e84e374cf29c9f1809d566d98b2cb933 (patch)
tree4af8cac41140a3c6e8657829b698d1ab6c5cee86
parente244bfa1c819e804b120ad49f37fce0aa802e529 (diff)
[FIX] sale,purchase: do not enforce company at _prepare_* level.
By specifying the with_company at a higher level: 1) The risk of multi-company conflicts decreases 2) We allow customizations to use _prepare_* methods to potentially create records in other companies when needed. closes odoo/odoo#55192 X-original-commit: 33c767e1778d2b1fc83aaaea92c3c2aa008b9520 Related: odoo/enterprise#12105 Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com> Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
-rw-r--r--addons/purchase/models/account_invoice.py2
-rw-r--r--addons/purchase/models/purchase.py2
-rw-r--r--addons/sale/models/sale.py8
-rw-r--r--addons/sale_purchase/models/sale_order.py1
4 files changed, 6 insertions, 7 deletions
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)