[IMP] product: clean res_partner.py

Part-of: odoo/odoo#82374
This commit is contained in:
Victor Feyens
2022-02-21 08:41:29 +00:00
parent 5a58ba9d1a
commit 06f417012c
+13 -8
View File
@@ -1,17 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api
from odoo import api, fields, models
class Partner(models.Model):
_name = 'res.partner'
class ResPartner(models.Model):
_inherit = 'res.partner'
# NOT A REAL PROPERTY !!!!
property_product_pricelist = fields.Many2one(
'product.pricelist', 'Pricelist', compute='_compute_product_pricelist',
inverse="_inverse_product_pricelist", company_dependent=False,
comodel_name='product.pricelist',
string="Pricelist",
compute='_compute_product_pricelist',
inverse="_inverse_product_pricelist",
company_dependent=False,
domain=lambda self: [('company_id', 'in', (self.env.company.id, False))],
help="This pricelist will be used, instead of the default one, for sales to the current partner")
@@ -29,8 +31,11 @@ class Partner(models.Model):
[('country_group_ids.country_ids.code', '=', partner.country_id and partner.country_id.code or False)],
limit=1
)
default_for_country = pls and pls[0]
actual = self.env['ir.property']._get('property_product_pricelist', 'res.partner', 'res.partner,%s' % partner.id)
default_for_country = pls
actual = self.env['ir.property']._get(
'property_product_pricelist',
'res.partner',
'res.partner,%s' % partner.id)
# update at each change country, and so erase old pricelist
if partner.property_product_pricelist or (actual and default_for_country and default_for_country.id != actual.id):
# keep the company of the current user before sudo
@@ -42,4 +47,4 @@ class Partner(models.Model):
)
def _commercial_fields(self):
return super(Partner, self)._commercial_fields() + ['property_product_pricelist']
return super()._commercial_fields() + ['property_product_pricelist']