[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>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user