From df96a8f2921e8f30149dd1007f884b270ff2991a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Wed, 3 Mar 2021 17:29:21 +0000 Subject: [PATCH] [FIX] account: fix default context for `group_id` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: - Activate "Analytic Tags" and "Analytic Accounting" Settings - Create an Analytic Tags and select "Analytic Distribution" - Create Product -> Product type: Storable product, Update Quantity as 100, Sales Price like 100 - Product category -> Costing Method: Average Cost (AVCO) Inventory Valuation: Automated - Create Analytic Defaults Rules -> select created Analytic Tags & Product. - Create a SO -> Confirm it -> Delivery -> Validate it then system give validation message message: "The operation cannot be completed: another model requires the record being deleted. If possible, archive it instead. Model: Analytic Line (account.analytic.line), Constraint: account_analytic_line_group_id_fkey” But can be validated from the Inventory app. Technical information: It is due to the `default_group_id` in context put in `action_view_delivery` method, it context key allows to create delivery (tree view of `stock.picking`) with the correct `group_id` ("Procurement Group"). But the this name field is also used in the `account.analytic.line` model. Moreover, the the `_prepare_analytic_distribution_line` doesn't return any value for `group_id` which means, that at the creation of the `account.analytic.line` the `group_id` (id of `procurement.group`) which will wrongly used. Solution: Because the `group_id` field on `account.analytic.line` is a related store of `account_id.group_id`. We can set it directly in the `_prepare_analytic_distribution_line` with the correct value. opw-2442493 closes odoo/odoo#67780 X-original-commit: c9f55c5ecf174414f8e9ed6df56170ac2c6d6e3e Signed-off-by: William André (wan) --- addons/account/models/account_move.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 93a107b57ca..74f06029dc1 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -4824,6 +4824,7 @@ class AccountMoveLine(models.Model): 'name': default_name, 'date': self.date, 'account_id': distribution.account_id.id, + 'group_id': distribution.account_id.group_id.id, 'partner_id': self.partner_id.id, 'tag_ids': [(6, 0, [distribution.tag_id.id] + self._get_analytic_tag_ids())], 'unit_amount': self.quantity,