From 33bb316577de29e61444ce6e14a305fd38c3f50d Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 16 Jan 2020 09:00:35 +0000 Subject: [PATCH] [FIX] account_analytic_default_purchase: access error - Activate Analytic Accounting - Set the demo user with only the Purchase User access rights (no accounting access rights) - Create a PO with demo An AccessError is raised because the user has no access to `account.analytic.default`. We can use `sudo` to retrieve the default account. There is no access rights error on `account_analytic_id` or `analytic_tag_ids` later on. Fix the `company_id` at the same time. opw-2171813 closes odoo/odoo#43431 X-original-commit: ef5cc35b50e54ea3d161897bbb089dedb68e36a1 Signed-off-by: Nicolas Martinelli (nim) --- .../models/purchase_order_line.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/account_analytic_default_purchase/models/purchase_order_line.py b/addons/account_analytic_default_purchase/models/purchase_order_line.py index f2c3c96f53e..7a5d4ae80be 100644 --- a/addons/account_analytic_default_purchase/models/purchase_order_line.py +++ b/addons/account_analytic_default_purchase/models/purchase_order_line.py @@ -9,7 +9,13 @@ class PurchaseOrderLine(models.Model): @api.onchange('product_id', 'date_order') def _onchange_product_id_date(self): - default_analytic_account = self.env['account.analytic.default'].account_get(product_id=self.product_id.id, partner_id=self.order_id.partner_id.id, user_id=self.env.uid, date=self.date_order) + default_analytic_account = self.env['account.analytic.default'].sudo().account_get( + product_id=self.product_id.id, + partner_id=self.order_id.partner_id.id, + user_id=self.env.uid, + date=self.date_order, + company_id=self.company_id.id, + ) if default_analytic_account: self.account_analytic_id = default_analytic_account.analytic_id.id self.analytic_tag_ids = [(6, 0, default_analytic_account.analytic_tag_ids.ids)]