Sélectionner une révision Git
account_move.py 2,91 Kio
# Copyright 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from odoo.exceptions import UserError
class ScopAccountMove(models.Model):
_inherit = "account.move"
move_line_payment_ids = fields.One2many(
comodel_name="account.move.line",
string="Paiements",
compute="_compute_move_line_payment_ids",
)
vat = fields.Char(related="partner_id.vat", string="N° TVA")
# ------------------------------------------------------
# Compute functions
# ------------------------------------------------------
def _compute_move_line_payment_ids(self):
for move in self:
values = move._get_reconciled_info_JSON_values()
aml = []
for value in values:
aml.append(value.get("payment_id"))
aml_deduplicated = list(set(aml))
move.move_line_payment_ids = move.line_ids.browse(aml_deduplicated)
# ------------------------------------------------------
# Onchange functions
# ------------------------------------------------------
@api.onchange("partner_id")
def _onchange_partner_id(self):
super(ScopAccountMove, self)._onchange_partner_id()
domain = {
"domain": {
"partner_id": [
("is_company", "=", True),
("type", "!=", "facility"),
("ur_id", "in", self.company_id.invoice_ur_ids.ids),
]
}
}
return domain
# ------------------------------------------------------
# Button functions
# ------------------------------------------------------
def get_partner_vat(self):
for invoice in self:
invoice.partner_id.get_vat()
# ------------------------------------------------------
# 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")
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()._post(soft)