[FIX] stock_account: COGS and reconciliation

Commit 98ee15977a 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) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-05-14 06:55:04 +00:00
parent 476a53bbf0
commit c92b0ce303
2 changed files with 38 additions and 0 deletions
+1
View File
@@ -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
@@ -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