se adiciona mas modelos a nuevo esquema

FossilOrigin-Name: acac57e60f808abdd89937be338d819f4f6fa9f8b4dda725569f445f96c982d3
This commit is contained in:
bit4bit 2021-06-26 22:05:30 +00:00
parent 1d6d1e2601
commit 4f15926656
4 changed files with 51 additions and 7 deletions

View File

@ -2,6 +2,9 @@ import facho.model as model
import facho.model.fields as fields import facho.model.fields as fields
from datetime import date, datetime from datetime import date, datetime
class Name(model.Model):
__name__ = 'Name'
class Date(model.Model): class Date(model.Model):
__name__ = 'Date' __name__ = 'Date'
@ -51,23 +54,60 @@ class InvoicedQuantity(model.Model):
code = fields.Attribute('unitCode', default='NAR') code = fields.Attribute('unitCode', default='NAR')
class PriceAmount(model.Model): class Amount(model.Model):
__name__ = 'PriceAmount' __name__ = 'Amount'
currency = fields.Attribute('currencyID', default='COP') currency = fields.Attribute('currencyID', default='COP')
class Price(model.Model): class Price(model.Model):
__name__ = 'Price' __name__ = 'Price'
amount = fields.Many2One(PriceAmount) amount = fields.Many2One(Amount, name='PriceAmount')
def __default_set__(self, value): def __default_set__(self, value):
self.amount = value self.amount = value
class Percent(model.Model):
__name__ = 'Percent'
class TaxScheme(model.Model):
__name__ = 'TaxScheme'
id = fields.Many2One(ID)
name= fields.Many2One(Name)
class TaxCategory(model.Model):
__name__ = 'TaxCategory'
percent = fields.Many2One(Percent, default='19.0')
tax_scheme = fields.Many2One(TaxScheme)
class TaxSubTotal(model.Model):
__name__ = 'TaxSubTotal'
taxable_amount = fields.Many2One(Amount, name='TaxableAmount')
tax_amount = fields.Many2One(Amount, name='TaxAmount')
tax_category = fields.Many2One(TaxCategory)
percent = fields.Virtual(setter='set_percent')
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):
__name__ = 'TaxTotal'
tax_amount = fields.Many2One(Amount, name='TaxAmount')
subtotals = fields.One2Many(TaxSubTotal)
class InvoiceLine(model.Model): class InvoiceLine(model.Model):
__name__ = 'InvoiceLine' __name__ = 'InvoiceLine'
quantity = fields.Many2One(InvoicedQuantity) quantity = fields.Many2One(InvoicedQuantity)
taxtotal = fields.Many2One(TaxTotal)
price = fields.Many2One(Price) price = fields.Many2One(Price)
class Invoice(model.Model): class Invoice(model.Model):

View File

@ -38,6 +38,7 @@ class ModelBase(object, metaclass=ModelMeta):
# forzamos registros de campos al modelo # forzamos registros de campos al modelo
# al instanciar # al instanciar
for (key, v) in type(obj).__dict__.items(): for (key, v) in type(obj).__dict__.items():
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):
if hasattr(v, 'default') and v.default is not None: if hasattr(v, 'default') and v.default is not None:
setattr(obj, key, v.default) setattr(obj, key, v.default)
@ -97,7 +98,7 @@ class ModelBase(object, metaclass=ModelMeta):
content = "" content = ""
for name, value in self._fields.items(): for value in self._fields.values():
if hasattr(value, 'to_xml'): if hasattr(value, 'to_xml'):
content += value.to_xml() content += value.to_xml()
elif isinstance(value, str): elif isinstance(value, str):

View File

@ -19,7 +19,6 @@ class _RelationProxy():
# algo burdo, se usa __dict__ para saltarnos el __getattr__ y generar un fallo por recursion # algo burdo, se usa __dict__ para saltarnos el __getattr__ y generar un fallo por recursion
for fun in self.__dict__['_inst']._on_change_fields[self.__dict__['_attribute']]: for fun in self.__dict__['_inst']._on_change_fields[self.__dict__['_attribute']]:
fun(self.__dict__['_inst'], self.__dict__['_attribute'], value) fun(self.__dict__['_inst'], self.__dict__['_attribute'], value)
return setattr(self._obj, attr, value) return setattr(self._obj, attr, value)
class _Relation(): class _Relation():

View File

@ -21,6 +21,10 @@ def test_simple_invoice():
line = invoice.lines.create() line = invoice.lines.create()
line.quantity = form.Quantity(1, '94') line.quantity = form.Quantity(1, '94')
subtotal = line.taxtotal.subtotals.create()
subtotal.percent = 19.0
# TODO(bit4bit) el orden de los elementos
# en el xml lo debe determinar la declaracion en los modelos
line.price = form.Amount(5_000) line.price = form.Amount(5_000)
assert '<Invoice><ID>323200000129</ID><IssueDate>2019-01-16T10:53:10-05:00</IssueDate><IssueTime>10:5310-05:00</IssueTime><AccountingSupplierParty><Party><ID>700085371</ID></Party></AccountingSupplierParty><AccountingCustomerParty><Party><ID>800199436</ID></Party></AccountingCustomerParty><InvoiceLine><InvoiceQuantity unitCode="NAR">1.0</InvoiceQuantity><Price><PriceAmount currencyID="COP">5000.0</PriceAmount></Price></InvoiceLine></Invoice>' == invoice.to_xml() assert '<Invoice><ID>323200000129</ID><IssueDate>2019-01-16T10:53:10-05:00</IssueDate><IssueTime>10:5310-05:00</IssueTime><AccountingSupplierParty><Party><ID>700085371</ID></Party></AccountingSupplierParty><AccountingCustomerParty><Party><ID>800199436</ID></Party></AccountingCustomerParty><InvoiceLine><InvoiceQuantity unitCode="NAR">1.0</InvoiceQuantity><TaxTotal><TaxSubTotal><TaxCategory><Percent>19.0</Percent><TaxScheme><ID>01</ID><Name>IVA</Name></TaxScheme></TaxCategory></TaxSubTotal></TaxTotal><Price><PriceAmount currencyID="COP">5000.0</PriceAmount></Price></InvoiceLine></Invoice>' == invoice.to_xml()