summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorDenis Ledoux <dle@odoo.com>2019-03-11 16:56:09 +0000
committerDenis Ledoux <dle@odoo.com>2019-03-11 17:22:09 +0000
commitd3453f7d152d486cb5df01b4e40dbde57f59b49e (patch)
tree2510c5630c3efea299cf3ba3648685611a269c5d /addons
parentb3c3ed3a09c31c7f9bad9ccd96b42651a91b6863 (diff)
[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>
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/account_move.py5
-rw-r--r--addons/point_of_sale/models/pos_order.py9
2 files changed, 11 insertions, 3 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 10fd1b879dc..176a84722a5 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -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
diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py
index 4841831630c..c0da3fb1e3f 100644
--- a/addons/point_of_sale/models/pos_order.py
+++ b/addons/point_of_sale/models/pos_order.py
@@ -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']