diff --git a/models/account_move.py b/models/account_move.py index 7fce870e437eb6232fe1febaf802f7085b5cc1c4..1b4c420ba3ba46cdb994adbf11c7fa6736191f91 100644 --- a/models/account_move.py +++ b/models/account_move.py @@ -2,7 +2,8 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, fields, models -from odoo.exceptions import UserError, ValidationError +from odoo.exceptions import UserError + class ScopAccountMove(models.Model): _inherit = "account.move" @@ -50,27 +51,26 @@ class ScopAccountMove(models.Model): for invoice in self: invoice.partner_id.get_vat() - # ------------------------------------------------------ - # Override confirm button action + # Inherit parent # ------------------------------------------------------ def _post(self, soft=True): - + """ + Vérifie le compte client pour OPM + """ # On effectue qq tests spécifiques à l'UR OPM - ur_opm = self.env.ref("cgscop_partner.riga_14243").id - current_ur = self.env["res.company"]._ur_default_get().id + ur_opm = self.env.ref("cgscop_partner.riga_14243") - if current_ur == ur_opm: - for rec in self: - if rec.partner_id: - # On doit avoir un no de compte pour le client - if not rec.partner_id.property_account_receivable_id: - raise UserError("Numéro de compte comptable client obligatoire.") - # Qui ne doit pas être le 411 par défaut - if rec.partner_id.property_account_receivable_id.code.startswith('411'): - raise UserError("Numéro de compte client invalide.") - # Et d'une longueur <= 7 - if len(rec.partner_id.property_account_receivable_id.code) > 7: - raise UserError("Numéro de compte client trop long.") + for move in self: + if move.partner_id and move.company_id.ur_id == ur_opm: + # On doit avoir un no de compte pour le client + if not move.partner_id.property_account_receivable_id: + raise UserError("Numéro de compte comptable client obligatoire.") + # Qui ne doit pas être le 411 par défaut + if move.partner_id.property_account_receivable_id.code.startswith('411'): + raise UserError("Numéro de compte client invalide.") + # Et d'une longueur <= 7 + if len(move.partner_id.property_account_receivable_id.code) > 7: + raise UserError("Numéro de compte client trop long.") - return super(ScopAccountMove,self)._post(soft) + return super()._post(soft)