From 31e610f7a341eca88065951ed362ac7cf66d63cb Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 18 Nov 2021 13:07:25 +0000 Subject: [PATCH] [FIX] purchase, sale: Fix multicompany fiscal pos access Context ------- On some database, record rule may be configured in such a way that user are able to read Purchase/Sale order with a company_id != user.company_ids Issue ----- This commit https://github.com/odoo/odoo/commit/4dd150950274b1d7c3b24b7665443318f94323f6# introduce a new field tax_country_id that require to be able to read the fiscal.position as well. The reading of a sale.order or purchase.order should not require the right to read the fiscal.position for the computation of a technical field only use during the modification. Solution -------- Compute tax_country_id as sudo closes odoo/odoo#80049 X-original-commit: b329c3b18197ac6db5ffdf3cb4945a14997a1f0b Signed-off-by: Olivier Dony Signed-off-by: Thibault Francois --- addons/purchase/models/purchase.py | 2 ++ addons/sale/models/sale_order.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index ac367bffa41..b8c0e80a31d 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -125,6 +125,8 @@ class PurchaseOrder(models.Model): tax_country_id = fields.Many2one( comodel_name='res.country', compute='_compute_tax_country_id', + # Avoid access error on fiscal position, when reading a purchase order with company != user.company_ids + compute_sudo=True, help="Technical field to filter the available taxes depending on the fiscal country and fiscal position.") payment_term_id = fields.Many2one('account.payment.term', 'Payment Terms', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") incoterm_id = fields.Many2one('account.incoterms', 'Incoterm', states={'done': [('readonly', True)]}, help="International Commercial Terms are a series of predefined commercial terms used in international transactions.") diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 7d1e4dfe5cf..f668729c711 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -238,6 +238,8 @@ class SaleOrder(models.Model): tax_country_id = fields.Many2one( comodel_name='res.country', compute='_compute_tax_country_id', + # Avoid access error on fiscal position when reading a sale order with company != user.company_ids + compute_sudo=True, help="Technical field to filter the available taxes depending on the fiscal country and fiscal position.") company_id = fields.Many2one('res.company', 'Company', required=True, index=True, default=lambda self: self.env.company) team_id = fields.Many2one(