From c25a9ea2cc4de824ab1f7f06b60dd7f77b57cc94 Mon Sep 17 00:00:00 2001 From: Andreas Osim Date: Tue, 4 Jun 2019 15:10:06 +0200 Subject: [PATCH] change behaviour of property_product_pricelist (constraint) --- ext/custom-addons/dp_custom/models/res_partner.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ext/custom-addons/dp_custom/models/res_partner.py b/ext/custom-addons/dp_custom/models/res_partner.py index 00edc208..0843bd04 100644 --- a/ext/custom-addons/dp_custom/models/res_partner.py +++ b/ext/custom-addons/dp_custom/models/res_partner.py @@ -80,7 +80,7 @@ class Partner(models.Model): # make pricelist searchable (store=True) --> code copied from: \ext\odoo\addons\product\models\res_partner.py! property_product_pricelist = fields.Many2one( - 'product.pricelist', 'Sale Pricelist', compute='_compute_product_pricelist', store=True, required=True, default=1, + 'product.pricelist', 'Sale Pricelist', compute='_compute_product_pricelist', store=True, default=1, inverse="_inverse_product_pricelist", company_dependent=False, # NOT A REAL PROPERTY help="This pricelist will be used, instead of the default one, for sales to the current partner") @@ -89,6 +89,14 @@ class Partner(models.Model): ('portal_id_uniq', 'unique(portal_id)', 'Die Portal-ID muss eindeutig sein') ] + @api.multi + @api.constrains('property_product_pricelist') + def _check_property_product_pricelist(self): + for record in self: + if not record.parent_id.id and not record.property_product_pricelist: +# Here we have to set partner_id.property_product_pricelist if it es empty and a parent_id is existing - else we rise an error + raise ValidationError(_("Ungültige Preisliste!")) + @api.multi def _get_warn_date(self): for record in self: