trytondo-analytic_operations/invoice.py

43 lines
1.5 KiB
Python

# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import PoolMeta
from trytond.model import fields
from trytond.pyson import Eval
from trytond.model.exceptions import ValidationError
class Invoice(metaclass=PoolMeta):
'Account Invoice'
__name__ = 'account.invoice'
_states = {
'readonly': Eval('state') != 'draft',
}
account_analytic = fields.Many2One(
'analytic_account.account', 'Analytic Account',
domain=[('type', '=', 'normal')],
states=_states)
class InvoiceLine(metaclass=PoolMeta):
'Invoice Line'
__name__ = 'account.invoice.line'
@fields.depends(
'product', 'unit', '_parent_invoice.type', 'analytic_accounts',
'_parent_invoice.party', 'party', 'invoice', 'invoice_type',
'_parent_invoice.account_analytic', '_parent_invoice.invoice_date',
'_parent_invoice.accounting_date', 'company',
methods=['_get_tax_rule_pattern'])
def on_change_product(self):
super(InvoiceLine, self).on_change_product()
self.analytic_accounts = tuple()
try:
if self.invoice and self.invoice.account_analytic:
self.analytic_accounts += (
{'root': self.invoice.account_analytic.root,
'account': self.invoice.account_analytic},)
except Exception as e:
raise ValidationError(f"Se produjo un error: {e}")