se adiciona __setup__ para inicializar modelos
FossilOrigin-Name: 504ad84bee1c708c2b55fdde3552d39980bf1efad3a51de8050018e4d1f387f3
This commit is contained in:
parent
b3e4a088b7
commit
a1a9746353
@ -111,13 +111,17 @@ class TaxSubTotal(model.Model):
|
|||||||
tax_amount = fields.Many2One(Amount, name='TaxAmount')
|
tax_amount = fields.Many2One(Amount, name='TaxAmount')
|
||||||
tax_category = fields.Many2One(TaxCategory)
|
tax_category = fields.Many2One(TaxCategory)
|
||||||
|
|
||||||
percent = fields.Virtual(setter='set_percent')
|
percent = fields.Virtual(setter='set_category')
|
||||||
|
scheme = fields.Virtual(setter='set_category')
|
||||||
|
def set_category(self, name, value):
|
||||||
|
if name == 'percent':
|
||||||
|
self.tax_category.percent = value
|
||||||
|
# TODO(bit4bit) hacer variable
|
||||||
|
self.tax_category.tax_scheme.id = '01'
|
||||||
|
self.tax_category.tax_scheme.name = 'IVA'
|
||||||
|
elif name == 'scheme':
|
||||||
|
self.tax_category.tax_scheme.id = value
|
||||||
|
|
||||||
def set_percent(self, name, value):
|
|
||||||
self.tax_category.percent = value
|
|
||||||
# TODO(bit4bit) hacer variable
|
|
||||||
self.tax_category.tax_scheme.id = '01'
|
|
||||||
self.tax_category.tax_scheme.name = 'IVA'
|
|
||||||
|
|
||||||
class TaxTotal(model.Model):
|
class TaxTotal(model.Model):
|
||||||
__name__ = 'TaxTotal'
|
__name__ = 'TaxTotal'
|
||||||
@ -186,6 +190,8 @@ class Invoice(model.Model):
|
|||||||
lines = fields.One2Many(InvoiceLine)
|
lines = fields.One2Many(InvoiceLine)
|
||||||
legal_monetary_total = fields.Many2One(LegalMonetaryTotal)
|
legal_monetary_total = fields.Many2One(LegalMonetaryTotal)
|
||||||
|
|
||||||
|
cufe = fields.Virtual()
|
||||||
|
|
||||||
@fields.on_change(['lines'])
|
@fields.on_change(['lines'])
|
||||||
def update_legal_monetary_total(self, name, value):
|
def update_legal_monetary_total(self, name, value):
|
||||||
for line in self.lines:
|
for line in self.lines:
|
||||||
|
@ -51,6 +51,8 @@ class ModelBase(object, metaclass=ModelMeta):
|
|||||||
for field in on_change_fields:
|
for field in on_change_fields:
|
||||||
obj._on_change_fields[field].append(fun)
|
obj._on_change_fields[field].append(fun)
|
||||||
|
|
||||||
|
|
||||||
|
obj.__setup__()
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _set_attribute(self, field, name, value):
|
def _set_attribute(self, field, name, value):
|
||||||
@ -141,4 +143,8 @@ class Model(ModelBase):
|
|||||||
"""
|
"""
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def __setup__(self):
|
||||||
|
"""
|
||||||
|
Inicializar modelo
|
||||||
|
"""
|
||||||
|
|
||||||
|
@ -506,3 +506,15 @@ def test_field_amount():
|
|||||||
|
|
||||||
assert '<Line amount="33"/>' == line.to_xml()
|
assert '<Line amount="33"/>' == line.to_xml()
|
||||||
|
|
||||||
|
|
||||||
|
def test_model_setup():
|
||||||
|
class Line(facho.model.Model):
|
||||||
|
__name__ = 'Line'
|
||||||
|
|
||||||
|
amount = fields.Attribute(name='amount')
|
||||||
|
|
||||||
|
def __setup__(self):
|
||||||
|
self.amount = 23
|
||||||
|
|
||||||
|
line = Line()
|
||||||
|
assert '<Line amount="23"/>' == line.to_xml()
|
||||||
|
@ -36,5 +36,8 @@ def _test_simple_invoice_cufe():
|
|||||||
line = invoice.lines.create()
|
line = invoice.lines.create()
|
||||||
line.quantity = 1
|
line.quantity = 1
|
||||||
line.price = 1_500_000
|
line.price = 1_500_000
|
||||||
subtotal = line.taxtotal.subtotals.create()
|
line_subtotal = line.taxtotal.subtotals.create()
|
||||||
subtotal.percent = 19.0
|
line_subtotal.percent = 19.0
|
||||||
|
line.subtotal.scheme = '01'
|
||||||
|
|
||||||
|
assert invoice.cufe == '8bb918b19ba22a694f1da11c643b5e9de39adf60311cf179179e9b33381030bcd4c3c3f156c506ed5908f9276f5bd9b4'
|
||||||
|
Loading…
Reference in New Issue
Block a user