[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 <odo@odoo.com>
Signed-off-by: Thibault Francois <tfr@odoo.com>
This commit is contained in:
Thibault Francois
2021-12-21 13:46:55 +00:00
parent c510df4201
commit 31e610f7a3
2 changed files with 4 additions and 0 deletions
+2
View File
@@ -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.")
+2
View File
@@ -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(