se adicion campo fields.Amount
FossilOrigin-Name: b23b2c243daaf0788cf47736015d75eecae9f4eb55cd4d31b9e063d7fa9a0691
This commit is contained in:
parent
507ddbe558
commit
b3e4a088b7
@ -42,7 +42,7 @@ class ModelBase(object, metaclass=ModelMeta):
|
||||
if isinstance(v, fields.Field):
|
||||
obj._order_fields.append(key)
|
||||
|
||||
if isinstance(v, fields.Attribute) or isinstance(v, fields.Many2One) or isinstance(v, fields.Function):
|
||||
if isinstance(v, fields.Attribute) or isinstance(v, fields.Many2One) or isinstance(v, fields.Function) or isinstance(v, fields.Amount):
|
||||
if hasattr(v, 'default') and v.default is not None:
|
||||
setattr(obj, key, v.default)
|
||||
|
||||
|
@ -4,8 +4,9 @@ from .one2many import One2Many
|
||||
from .function import Function
|
||||
from .virtual import Virtual
|
||||
from .field import Field
|
||||
from .amount import Amount
|
||||
|
||||
__all__ = [Attribute, One2Many, Many2One, Virtual, Field]
|
||||
__all__ = [Attribute, One2Many, Many2One, Virtual, Field, Amount]
|
||||
|
||||
def on_change(fields):
|
||||
from functools import wraps
|
||||
|
@ -489,3 +489,20 @@ def test_model_attributes_order():
|
||||
|
||||
assert '<Invoice><Line1 quantity="1"/><Line2 quantity="2"/><Line3 quantity="3"/></Invoice>' == invoice.to_xml()
|
||||
|
||||
|
||||
def test_field_amount():
|
||||
class Line(facho.model.Model):
|
||||
__name__ = 'Line'
|
||||
|
||||
amount = fields.Amount(name='Amount', precision=0)
|
||||
amount_as_attribute = fields.Attribute('amount')
|
||||
|
||||
@fields.on_change(['amount'])
|
||||
def on_amount(self, name, value):
|
||||
self.amount_as_attribute = self.amount
|
||||
|
||||
line = Line()
|
||||
line.amount = 33
|
||||
|
||||
assert '<Line amount="33"/>' == line.to_xml()
|
||||
|
||||
|
@ -34,7 +34,7 @@ def _test_simple_invoice_cufe():
|
||||
invoice.customer.party.id = '800199436'
|
||||
|
||||
line = invoice.lines.create()
|
||||
line.quantity = form.Quantity(1, '94')
|
||||
line.price = form.Amount(1_500_000)
|
||||
line.quantity = 1
|
||||
line.price = 1_500_000
|
||||
subtotal = line.taxtotal.subtotals.create()
|
||||
subtotal.percent = 19.0
|
||||
|
Loading…
Reference in New Issue
Block a user