[FIX] account, pos: speed cash basis entries

Which was basically creating n² account move lines.

If a POS session has 100 orders with each 10 lines,
100 * 100 * 10 account move lines were being created.

closes odoo/odoo#31736

Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
This commit is contained in:
Denis Ledoux
2019-03-11 17:22:09 +00:00
parent b3c3ed3a09
commit d3453f7d15
2 changed files with 11 additions and 3 deletions
+3 -2
View File
@@ -1904,12 +1904,13 @@ class AccountPartialReconcile(models.Model):
# Get value of matched percentage from both move before reconciliating
lines = self.env['account.move.line'].browse(aml)
lines._payment_invoice_match()
if lines[0].account_id.internal_type in ('receivable', 'payable'):
tax_cash_basis_entry = not self.env.context.get('skip_tax_cash_basis_entry') and lines[0].account_id.internal_type in ('receivable', 'payable')
if tax_cash_basis_entry:
percentage_before_rec = lines._get_matched_percentage()
# Reconcile
res = super(AccountPartialReconcile, self).create(vals)
# if the reconciliation is a matching on a receivable or payable account, eventually create a tax cash basis entry
if lines[0].account_id.internal_type in ('receivable', 'payable'):
if tax_cash_basis_entry:
res.create_tax_cash_basis_entry(percentage_before_rec)
res._compute_partial_lines()
return res
+8 -1
View File
@@ -482,6 +482,7 @@ class PosOrder(models.Model):
return - price_unit
def _reconcile_payments(self):
cash_basis_percentage_before_rec = {move: move.line_ids._get_matched_percentage() for move in self.mapped('account_move')}
for order in self:
aml = order.statement_ids.mapped('journal_entry_ids') | order.account_move.line_ids | order.invoice_id.move_id.line_ids
aml = aml.filtered(lambda r: not r.reconciled and r.account_id.internal_type == 'receivable' and r.partner_id == order.partner_id.commercial_partner_id)
@@ -490,7 +491,7 @@ class PosOrder(models.Model):
# Cash returns will be well reconciled
# Whereas freight returns won't be
# "c'est la vie..."
aml.reconcile()
aml.with_context(skip_tax_cash_basis_entry=True).reconcile()
except Exception:
# There might be unexpected situations where the automatic reconciliation won't
# work. We don't want the user to be blocked because of this, since the automatic
@@ -499,6 +500,12 @@ class PosOrder(models.Model):
# It may be interesting to have the Traceback logged anyway
# for debugging and support purposes
_logger.exception('Reconciliation did not work for order %s', order.name)
for move in self.mapped('account_move'):
partial_reconcile = self.env['account.partial.reconcile'].search([
'|',
('credit_move_id.move_id', '=', move.id),
('debit_move_id.move_id', '=', move.id)], limit=1)
partial_reconcile.create_tax_cash_basis_entry(cash_basis_percentage_before_rec[move])
def _filtered_for_reconciliation(self):
filter_states = ['invoiced', 'done']