se adicionan mas campos a Invoice.Party

FossilOrigin-Name: 033c6a3c0297c83c1d0bf2bb246f55fa7ce0d8aaa752f2ae3ec9515c763d61bf
This commit is contained in:
bit4bit 2021-10-06 01:08:01 +00:00
parent 6716efd121
commit 2e130d39e6
3 changed files with 75 additions and 5 deletions

View File

@ -20,16 +20,20 @@ class PhysicalLocation(model.Model):
class PartyTaxScheme(model.Model): class PartyTaxScheme(model.Model):
__name__ = 'PartyTaxScheme' __name__ = 'PartyTaxScheme'
registration_name = fields.Many2One(Name, name='RegistrationName', namespace='cbc')
company_id = fields.Many2One(ID, name='CompanyID', namespace='cbc') company_id = fields.Many2One(ID, name='CompanyID', namespace='cbc')
tax_level_code = fields.Many2One(ID, name='TaxLevelCode', namespace='cbc', default='ZZ') tax_level_code = fields.Many2One(ID, name='TaxLevelCode', namespace='cbc', default='ZZ')
class Party(model.Model): class Party(model.Model):
__name__ = 'Party' __name__ = 'Party'
id = fields.Virtual(setter='_on_set_id') id = fields.Virtual(setter='_on_set_id')
name = fields.Many2One(PartyName, namespace='cac')
tax_scheme = fields.Many2One(PartyTaxScheme, namespace='cac') tax_scheme = fields.Many2One(PartyTaxScheme, namespace='cac')
location = fields.Many2One(PhysicalLocation, namespace='cac') location = fields.Many2One(PhysicalLocation, namespace='cac')
contact = fields.Many2One(Contact, namespace='cac')
def _on_set_id(self, name, value): def _on_set_id(self, name, value):
self.tax_scheme.company_id = value self.tax_scheme.company_id = value
@ -43,7 +47,7 @@ class AccountingCustomerParty(model.Model):
class AccountingSupplierParty(model.Model): class AccountingSupplierParty(model.Model):
__name__ = 'AccountingSupplierParty' __name__ = 'AccountingSupplierParty'
party = fields.Many2One(Party) party = fields.Many2One(Party, namespace='cac')
class Quantity(model.Model): class Quantity(model.Model):
__name__ = 'Quantity' __name__ = 'Quantity'

View File

@ -3,7 +3,7 @@ import facho.model.fields as fields
from datetime import date, datetime from datetime import date, datetime
__all__ = ['Element', 'Name', 'Date', 'Time', 'Period', 'ID', 'Address', 'Country'] __all__ = ['Element', 'PartyName', 'Name', 'Date', 'Time', 'Period', 'ID', 'Address', 'Country', 'Contact']
class Element(model.Model): class Element(model.Model):
""" """
@ -71,3 +71,20 @@ class Address(model.Model):
#DIAN 1.7.-2020: CAJ10 #DIAN 1.7.-2020: CAJ10
city = fields.Many2One(Element, name='CityName', namespace='cbc') city = fields.Many2One(Element, name='CityName', namespace='cbc')
class PartyName(model.Model):
__name__ = 'PartyName'
name = fields.Many2One(Name, namespace='cbc')
def __default_set__(self, value):
self.name = value
return value
def __default_get__(self, name, value):
return self.name
class Contact(model.Model):
__name__ = 'Contact'
email = fields.Many2One(Name, name='ElectronicEmail', namespace='cbc')

View File

@ -8,11 +8,10 @@
from datetime import datetime from datetime import datetime
import pytest import pytest
from lxml import etree
import facho.fe.model as model import facho.fe.model as model
import facho.fe.form as form import facho.fe.form as form
from facho import fe from facho import fe
import helpers import helpers
def simple_invoice(): def simple_invoice():
@ -68,3 +67,53 @@ def test_dian_extension_authorization_provider():
assert provider_id.attrib['schemeAgencyName'] == 'CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' assert provider_id.attrib['schemeAgencyName'] == 'CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)'
assert provider_id.attrib['schemeAgencyID'] == '195' assert provider_id.attrib['schemeAgencyID'] == '195'
assert provider_id.text == '800197268' assert provider_id.text == '800197268'
def test_invoicesimple_xml_signed_using_fexml(monkeypatch):
invoice = simple_invoice()
xml = fe.FeXML.from_string(invoice.to_xml())
signer = fe.DianXMLExtensionSigner('./tests/example.p12')
print(xml.tostring())
with monkeypatch.context() as m:
import helpers
helpers.mock_urlopen(m)
xml.add_extension(signer)
elem = xml.get_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent/ds:Signature')
assert elem.text is not None
def test_invoice_supplier_party():
invoice = simple_invoice()
invoice.supplier.party.name = 'superfacho'
invoice.supplier.party.tax_scheme.registration_name = 'legal-superfacho'
invoice.supplier.party.contact.email = 'superfacho@etrivial.net'
xml = fe.FeXML.from_string(invoice.to_xml())
name = xml.get_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name')
assert name.text == 'superfacho'
name = xml.get_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName')
assert name.text == 'legal-superfacho'
name = xml.get_element('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:Contact/cbc:ElectronicEmail')
assert name.text == 'superfacho@etrivial.net'
def test_invoice_customer_party():
invoice = simple_invoice()
invoice.customer.party.name = 'superfacho-customer'
invoice.customer.party.tax_scheme.registration_name = 'legal-superfacho-customer'
invoice.customer.party.contact.email = 'superfacho@etrivial.net'
xml = fe.FeXML.from_string(invoice.to_xml())
name = xml.get_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyName/cbc:Name')
assert name.text == 'superfacho-customer'
name = xml.get_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:RegistrationName')
assert name.text == 'legal-superfacho-customer'
name = xml.get_element('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:Contact/cbc:ElectronicEmail')
assert name.text == 'superfacho@etrivial.net'