From c92b0ce3036dde24b638bb3fb5dd89d7afbd759f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 25 Apr 2019 13:47:41 +0000 Subject: [PATCH] [FIX] stock_account: COGS and reconciliation Commit 98ee15977a3d9d84d made the Stock Interim accounts reconciliable, and introduced auto-reconciliation of related entries. This has the advantage to clean-up entries in these accounts. However, since these accounts are reconciliable, the entries will show up in the manual reconciliation widget (expected) and the bank reconciliation widget (not expected). There are 2 cases where it causes issues: - after migration from v11, the entries were not reconciliced. Although this will be fixed in the near future, it is too late for already migrated databases - using MRP. A list of components i costing Xi might be used to create a finished product of cost Y != sum(Xi). Indeed, the routing cost has to be taken into account. In this case, the entries are not fully reconcilied. The result is that the bank reconciliation widget ends up with an growing number of unreconcilied lines, and in the end making it impossible to use. In order to work around the issue, we prevent any account used as a stock interim account to be included in the bank reconciliation widget. For performance reasons, we directly search the `ir.property` table for the corresponding accounts instead of filtering AML thanks to `excluded_ids`. Closes #32611 opw-1963025 opw-1967462 closes odoo/odoo#32957 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock_account/models/__init__.py | 1 + .../models/account_reconciliation_widget.py | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 addons/stock_account/models/account_reconciliation_widget.py diff --git a/addons/stock_account/models/__init__.py b/addons/stock_account/models/__init__.py index 707d4618bda..a11616c850a 100644 --- a/addons/stock_account/models/__init__.py +++ b/addons/stock_account/models/__init__.py @@ -4,6 +4,7 @@ from . import account_chart_template from . import account_invoice from . import account_move +from . import account_reconciliation_widget from . import product from . import stock from . import res_config_settings diff --git a/addons/stock_account/models/account_reconciliation_widget.py b/addons/stock_account/models/account_reconciliation_widget.py new file mode 100644 index 00000000000..44110053899 --- /dev/null +++ b/addons/stock_account/models/account_reconciliation_widget.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +from odoo import api, models +from odoo.osv import expression + + +class AccountReconciliation(models.AbstractModel): + _inherit = "account.reconciliation.widget" + + @api.model + def _domain_move_lines_for_reconciliation(self, st_line, aml_accounts, partner_id, excluded_ids=None, search_str=False): + def to_int(val): + try: + return int(val) + except (ValueError, TypeError): + return None + + domain = super()._domain_move_lines_for_reconciliation( + st_line, aml_accounts, partner_id, excluded_ids=excluded_ids, search_str=search_str + ) + acc_props = ( + "property_stock_account_input", + "property_stock_account_output", + "property_stock_account_input_categ_id", + "property_stock_account_output_categ_id", + ) + acc_ids = [ + (acc["value_reference"] or "").split(",")[-1] + for acc in self.env["ir.property"] + .sudo() + .search([("name", "in", acc_props), ("value_reference", "!=", False)]) + .read(["value_reference"]) + if to_int((acc["value_reference"] or "").split(",")[-1]) + ] + if acc_ids: + domain = expression.AND([domain, [("account_id.id", "not in", acc_ids)]]) + return domain