From b3e4a088b79e8ee1aa12a7851558a58204e10943 Mon Sep 17 00:00:00 2001 From: bit4bit Date: Sat, 3 Jul 2021 21:50:56 +0000 Subject: [PATCH] se adicion campo fields.Amount FossilOrigin-Name: b23b2c243daaf0788cf47736015d75eecae9f4eb55cd4d31b9e063d7fa9a0691 --- facho/model/__init__.py | 2 +- facho/model/fields/__init__.py | 3 ++- tests/test_model.py | 17 +++++++++++++++++ tests/test_model_invoice.py | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/facho/model/__init__.py b/facho/model/__init__.py index 0c2f73c..59b8d55 100644 --- a/facho/model/__init__.py +++ b/facho/model/__init__.py @@ -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) diff --git a/facho/model/fields/__init__.py b/facho/model/fields/__init__.py index 6e9408d..081f195 100644 --- a/facho/model/fields/__init__.py +++ b/facho/model/fields/__init__.py @@ -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 diff --git a/tests/test_model.py b/tests/test_model.py index f6ae1ee..7104920 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -489,3 +489,20 @@ def test_model_attributes_order(): assert '' == 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.to_xml() + diff --git a/tests/test_model_invoice.py b/tests/test_model_invoice.py index 6472fd0..79d3604 100644 --- a/tests/test_model_invoice.py +++ b/tests/test_model_invoice.py @@ -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