Hereda la validación de cuentas bancarias al crear la factura y pone la cuenta a False en vez de elevar un error.

En la base de datos de la ddt da un error creando una fatura de compra, asigna partner_bank_id a la cuenta de la compañia en vez de la cuenta del proveedor.
This commit is contained in:
snt 2021-09-15 17:40:42 +02:00
parent 9bd253a931
commit a1cfaeba74
3 changed files with 43 additions and 18 deletions

View file

@ -2,3 +2,4 @@ from . import stock_picking
from . import res_partner
from . import res_config_settings
from . import res_company
from . import account_invoice

View file

@ -0,0 +1,24 @@
# Copyright (C) 2021: Criptomart (<https://criptomart.net/>)
# @author: Criptomart (<tech@criptomart.net>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, Warning
_logger = logging.getLogger(__name__)
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
@api.constrains('partner_id', 'partner_bank_id')
def validate_partner_bank_id(self):
for record in self:
if record.partner_bank_id:
if record.type in ('in_invoice', 'out_refund') and record.partner_bank_id.partner_id != record.partner_id.commercial_partner_id:
_logger.warning(_("Commercial partner and vendor account owners must be identical."))
record.partner_bank_id = False
elif record.type in ('out_invoice', 'in_refund') and not record.company_id in record.partner_bank_id.partner_id.ref_company_ids:
raise ValidationError(_("The account selected for payment does not belong to the same company as this invoice."))

View file

@ -107,9 +107,9 @@ class ResPartner(models.Model):
'type': 'in_invoice',
'date_invoice': self.deposit_buy_last_liquidation_date.strftime("%Y-%m-%d %H:%M:%S"),
'journal_id': self.env.user.company_id.deposit_journal_id.id,
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id)], limit=1).id,
'partner_id': self.id,
'invoice_line_ids': product_list,
'company_id': self.company_id.id,
})
invoice = self.env['account.invoice'].create(invoice_vals)
views = [(self.env.ref('account.invoice_form').id, 'form')]