From f630a544c2070210125f678cdb4c26a4762565e9 Mon Sep 17 00:00:00 2001 From: bit4bit Date: Thu, 24 Jun 2021 02:11:33 +0000 Subject: [PATCH] se inicia modelo de facturacion usando nuevo esquema FossilOrigin-Name: 8e6c23e7baa837c64b81baaed342b07eaab7ab631302cd2a8fa86f4989227d07 --- facho/fe/model/__init__.py | 65 +++++++++++++++++++++++++++++++++++++ tests/test_model_invoice.py | 19 +++++++++++ 2 files changed, 84 insertions(+) create mode 100644 facho/fe/model/__init__.py create mode 100644 tests/test_model_invoice.py diff --git a/facho/fe/model/__init__.py b/facho/fe/model/__init__.py new file mode 100644 index 0000000..42536d6 --- /dev/null +++ b/facho/fe/model/__init__.py @@ -0,0 +1,65 @@ +import facho.model as model +import facho.model.fields as fields +from datetime import date, datetime + +class Date(model.Model): + __name__ = 'Date' + + def __default_set__(self, value): + if isinstance(value, str): + return value + if isinstance(value, date): + return value.isoformat() + +class Time(model.Model): + __name__ = 'Time' + + def __default_set__(self, value): + if isinstance(value, str): + return value + if isinstance(value, date): + return value.strftime('%H:%M%S-05:00') + +class InvoicePeriod(model.Model): + __name__ = 'InvoicePeriod' + + start_date = fields.Many2One(Date, name='StartDate') + + end_date = fields.Many2One(Date, name='EndDate') + +class ID(model.Model): + __name__ = 'ID' + +class Party(model.Model): + __name__ = 'Party' + + id = fields.Many2One(ID) + +class AccountingCustomerParty(model.Model): + __name__ = 'AccountingCustomerParty' + + party = fields.Many2One(Party) + +class AccountingSupplierParty(model.Model): + __name__ = 'AccountingSupplierParty' + + party = fields.Many2One(Party) + +class Invoice(model.Model): + __name__ = 'Invoice' + + id = fields.Many2One(ID) + issue = fields.Function(setter='set_issue') + issue_date = fields.Many2One(Date, name='IssueDate') + issue_time = fields.Many2One(Time, name='IssueTime') + + period = fields.Many2One(InvoicePeriod) + + supplier = fields.Many2One(AccountingSupplierParty) + customer = fields.Many2One(AccountingCustomerParty) + + def set_issue(self, name, value): + if not isinstance(value, datetime): + raise ValueError('expected type datetime') + self.issue_date = value + self.issue_time = value diff --git a/tests/test_model_invoice.py b/tests/test_model_invoice.py new file mode 100644 index 0000000..30f5b91 --- /dev/null +++ b/tests/test_model_invoice.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# This file is part of facho. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +"""Nuevo esquema para modelar segun decreto""" + +from datetime import datetime + +import pytest + +import facho.fe.model as model + +def test_simple_invoice(): + invoice = model.Invoice() + invoice.id = '323200000129' + invoice.issue = datetime.strptime('2019-01-16 10:53:10-05:00', '%Y-%m-%d %H:%M:%S%z') + invoice.supplier.party.id = '700085371' + invoice.customer.party.id = '800199436'