[FIX] account, purchase: performance when adding PO
- Create 5 PO with 40 lines each for Partner A - Create an invoice - Add each PO thanks to the field "Add Purchase Order" The process takes more and more time for each PO. Most of the time is spent in the recomputation of the secondary fields (in the `onchange` method of "models.py"). The root cause is the cache invalidation due to the relational fields recomputed as superuser by default. opw-740485
This commit is contained in:
@@ -1154,11 +1154,11 @@ class AccountInvoiceLine(models.Model):
|
||||
account_analytic_id = fields.Many2one('account.analytic.account',
|
||||
string='Analytic Account')
|
||||
company_id = fields.Many2one('res.company', string='Company',
|
||||
related='invoice_id.company_id', store=True, readonly=True)
|
||||
related='invoice_id.company_id', store=True, readonly=True, related_sudo=False)
|
||||
partner_id = fields.Many2one('res.partner', string='Partner',
|
||||
related='invoice_id.partner_id', store=True, readonly=True)
|
||||
currency_id = fields.Many2one('res.currency', related='invoice_id.currency_id', store=True)
|
||||
company_currency_id = fields.Many2one('res.currency', related='invoice_id.company_currency_id', readonly=True)
|
||||
related='invoice_id.partner_id', store=True, readonly=True, related_sudo=False)
|
||||
currency_id = fields.Many2one('res.currency', related='invoice_id.currency_id', store=True, related_sudo=False)
|
||||
company_currency_id = fields.Many2one('res.currency', related='invoice_id.company_currency_id', readonly=True, related_sudo=False)
|
||||
|
||||
@api.model
|
||||
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
|
||||
|
||||
@@ -67,10 +67,7 @@ class AccountInvoice(models.Model):
|
||||
self.partner_id = self.purchase_id.partner_id.id
|
||||
|
||||
new_lines = self.env['account.invoice.line']
|
||||
for line in self.purchase_id.order_line:
|
||||
# Load a PO line only once
|
||||
if line in self.invoice_line_ids.mapped('purchase_line_id'):
|
||||
continue
|
||||
for line in self.purchase_id.order_line - self.invoice_line_ids.mapped('purchase_line_id'):
|
||||
data = self._prepare_invoice_line_from_po_line(line)
|
||||
new_line = new_lines.new(data)
|
||||
new_line._set_additional_fields(self)
|
||||
@@ -198,5 +195,5 @@ class AccountInvoiceLine(models.Model):
|
||||
_inherit = 'account.invoice.line'
|
||||
|
||||
purchase_line_id = fields.Many2one('purchase.order.line', 'Purchase Order Line', ondelete='set null', index=True, readonly=True)
|
||||
purchase_id = fields.Many2one('purchase.order', related='purchase_line_id.order_id', string='Purchase Order', store=False, readonly=True,
|
||||
purchase_id = fields.Many2one('purchase.order', related='purchase_line_id.order_id', string='Purchase Order', store=False, readonly=True, related_sudo=False,
|
||||
help='Associated Purchase Order. Filled in automatically when a PO is chosen on the vendor bill.')
|
||||
|
||||
Reference in New Issue
Block a user