<commit_before>##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import api, models, _
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.one
    def _inverse_product_pricelist(self):
        """ if user is in group restrict prices we still allow him to create
        partners without pricelist or to delete pricelist from partners"""
        if self.user_has_groups('price_security.group_restrict_prices') and \
                self.property_product_pricelist:
            raise ValidationError(_(
                'You are not allowed to change the pricelist'))
        return super(ResPartner, self)._inverse_product_pricelist()

    @api.constrains('property_payment_term_id')
    def check_property_payment_term_id(self):
        """ if user is in group restrict prices we still allow him to create
        partners without payment term or to delete payment term from
        partners"""
        if self.user_has_groups(
                'price_security.group_restrict_prices') and \
                self.filtered(lambda x: x.property_payment_term_id):
            raise ValidationError(_(
                'You are not allowed to change the Payment Term'))<commit_msg>[FIX] only restring change the pricelist and the payment term if the partner and commercial partner are the same (#196)<commit_after>##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import api, models, _
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.one
    def _inverse_product_pricelist(self):
        """ if user is in group restrict prices we still allow him to create
        partners without pricelist or to delete pricelist from partners"""
        if self == self.commercial_partner_id and\
            self.user_has_groups('price_security.group_restrict_prices') and \
                self.property_product_pricelist:
            raise ValidationError(_(
                'You are not allowed to change the pricelist'))
        return super(ResPartner, self)._inverse_product_pricelist()

    @api.constrains('property_payment_term_id')
    def check_property_payment_term_id(self):
        """ if user is in group restrict prices we still allow him to create
        partners without payment term or to delete payment term from
        partners"""
        if self.user_has_groups(
                'price_security.group_restrict_prices') and \
                self.filtered(lambda x: x == x.commercial_partner_id
                              and x.property_payment_term_id):
            raise ValidationError(_(
                'You are not allowed to change the Payment Term'))
{'fraction_non_alphanumeric': 0.15814850530376084, 'fraction_numerical': 0.0009643201542912247, 'mean_word_length': 3.2571819425444595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4115005', 'n_tokens_mistral': 801, 'n_tokens_neox': 727, 'n_words': 250}