From 780b64789a097820c3a9efd1f36266dfeddb4db7 Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Fri, 18 May 2018 09:28:25 +0200 Subject: [PATCH] Add AdministrativeCentres task-034415 --- party.py | 4 + template_facturae_3.2.1.xml | 144 +++++++---------------------------- template_facturae_macros.xml | 60 +++++++++++++++ view/party_form.xml | 8 ++ 4 files changed, 101 insertions(+), 115 deletions(-) create mode 100644 template_facturae_macros.xml diff --git a/party.py b/party.py index 677c51f..de7f0f8 100644 --- a/party.py +++ b/party.py @@ -20,3 +20,7 @@ class Party: ('U', 'Resident in other EU country'), ('E', 'Foreigner'), ], 'Residence Type', sort=False) + oficina_contable = fields.Char('Oficina contable') + organo_gestor = fields.Char('Organo gestor') + unidad_tramitadora = fields.Char('Unidad tramitadora') + organo_proponente = fields.Char('Organo proponente') diff --git a/template_facturae_3.2.1.xml b/template_facturae_3.2.1.xml index dc0a494..22ffd63 100644 --- a/template_facturae_3.2.1.xml +++ b/template_facturae_3.2.1.xml @@ -1,4 +1,4 @@ - +{% from "template_facturae_macros.xml" import administrative_center, address, contact %} 3.2.1 @@ -43,52 +43,27 @@ {# Optional. It could be the ID or the code #} {% if invoice.company.party.code and invoice.company.party.code | length < 10 %} - {{ invoice.company.party.code }} + {{ invoice.company.party.code|int or invoice.company.party.id }} + {% endif %} + {% if invoice.company.party.oficina_contable or invoice.company.party.organo_gestor or invoice.company.party.unidad_tramitadora or invoice.company.party.organo_proponente %} + + {% if invoice.company.party.oficina_contable %}{{ administrative_center(invoice.company.party.oficina_contable, '01', invoice.company.party) }}{% endif %} + {% if invoice.company.party.organo_gestor %}{{ administrative_center(invoice.company.party.organo_gestor, '02', invoice.company.party) }}{% endif %} + {% if invoice.company.party.unidad_tramitadora %}{{ administrative_center(invoice.company.party.unidad_tramitadora, '03', invoice.company.party) }}{% endif %} + {% if invoice.company.party.organo_proponente %}{{ administrative_center(invoice.company.party.organo_proponente, '04', invoice.company.party) }}{% endif %} + {% endif %} - {# AdministrativeCentres optional: not supported #} {{ invoice.company.party.name[:80] }} {% if invoice.company.party.trade_name %} {{ invoice.company.party.trade_name[:40] }} {% endif %} {# RegistrationData optional: not supported #} - {% if invoice.company.party.addresses[0].country.code == 'ES' %} - -
{{ invoice.company.party.addresses[0].street[:80] }}
- {{ invoice.company.party.addresses[0].zip[:5] }} - {{ invoice.company.party.addresses[0].city[:50] }} - {{ invoice.company.party.addresses[0].subdivision.name[:20] }} - {{ invoice.company.party.addresses[0].country.code3 }} -
- {% else %} - -
{{ invoice.company.party.addresses[0].street[:80] }}
- {{ (', '.join(invoice.company.party.addresses[0].zip, invoice.company.party.addresses[0].city))[:50] }} - {{ invoice.company.party.addresses[0].subdivision.name[:20] }} - {{ invoice.company.party.addresses[0].country.code3 }} -
+ {% if invoice.company.party.addresses %} + {{ address(invoice.company.party.addresses[0]) }} {% endif %} - {% if invoice.company.party.phone or invoice.company.party.mobile or invoice.company.party.fax or invoice.company.party.website or invoice.company.party.email %} - - {% if invoice.company.party.phone or invoice.company.party.mobile %} - {{ (invoice.company.party.phone or invoice.company.party.mobile)[:15] }} - {% endif %} - {% if invoice.company.party.fax %} - {{ invoice.company.party.fax[:15] }} - {% endif %} - {% if invoice.company.party.website %} - {{ invoice.company.party.website[:60] }} - {% endif %} - {% if invoice.company.party.email %} - {{ invoice.company.party.email[:60] }} - {% endif %} - {# Optional: not supported - - - - - #} - + {% if invoice.company.party.contact_mechanisms %} + {{ contact(invoice.company.party) }} {% endif %}
@@ -101,9 +76,16 @@ {# Optional. It could be the ID or the code #} {% if invoice.party.code and invoice.party.code | length < 10 %} - {{ invoice.party.code }} + {{ invoice.party.code|int or invoice.party.id }} + {% endif %} + {% if invoice.party.oficina_contable or invoice.party.organo_gestor or invoice.party.unidad_tramitadora or invoice.party.organo_proponente %} + + {% if invoice.party.oficina_contable %}{{ administrative_center(invoice.party.oficina_contable, '01', invoice.party) }}{% endif %} + {% if invoice.party.organo_gestor %}{{ administrative_center(invoice.party.organo_gestor, '02', invoice.party) }}{% endif %} + {% if invoice.party.unidad_tramitadora %}{{ administrative_center(invoice.party.unidad_tramitadora, '03', invoice.party) }}{% endif %} + {% if invoice.party.organo_proponente %}{{ administrative_center(invoice.party.organo_proponente, '04', invoice.party) }}{% endif %} + {% endif %} - {# AdministrativeCentres optional: not supported #} {% if invoice.party.facturae_person_type == 'J' %} {{ invoice.party.name and invoice.party.name[:80] or invoice.party.code[:80] }} @@ -111,43 +93,9 @@ {{ invoice.party.trade_name[:40] }} {% endif %} {# RegistrationData optional: not supported #} - {% if invoice.invoice_address.country.code == 'ES' %} - -
{{ invoice.invoice_address.street[:80] }}
- {{ invoice.invoice_address.zip[:5] }} - {{ invoice.invoice_address.city[:50] }} - {{ invoice.invoice_address.subdivision.name[:20] }} - {{ invoice.invoice_address.country.code3 }} -
- {% else %} - -
{{ invoice.invoice_address.street[:80] }}
- {{ (', '.join(invoice.invoice_address.zip, invoice.invoice_address.city))[:50] }} - {{ invoice.invoice_address.subdivision.name[:20] }} - {{ invoice.invoice_address.country.code3 }} -
- {% endif %} - {% if invoice.party.phone or invoice.party.mobile or invoice.party.fax or invoice.party.website or invoice.party.email %} - - {% if invoice.party.phone or invoice.party.mobile %} - {{ (invoice.party.phone or invoice.party.mobile)[:15] }} - {% endif %} - {% if invoice.party.fax %} - {{ invoice.party.fax[:15] }} - {% endif %} - {% if invoice.party.website %} - {{ invoice.party.website[:60] }} - {% endif %} - {% if invoice.party.email %} - {{ invoice.party.email[:60] }} - {% endif %} - {# Optional: not supported - - - - - #} - + {{ address(invoice.invoice_address) }} + {% if invoice.party.contact_mechanisms %} + {{ contact(invoice.party) }} {% endif %}
{% else %} @@ -158,43 +106,9 @@ {{ invoice.party.name and invoice.party.name.split(' ', 2)[2][:40] }} {% endif %} {# RegistrationData optional: not supported #} - {% if invoice.invoice_address.country.code == 'ES' %} - -
{{ invoice.invoice_address.street[:80] }}
- {{ invoice.invoice_address.zip[:5] }} - {{ invoice.invoice_address.city[:50] }} - {{ invoice.invoice_address.subdivision.name[:20] }} - {{ invoice.invoice_address.country.code3 }} -
- {% else %} - -
{{ invoice.invoice_address.street[:80] }}
- {{ (', '.join(invoice.invoice_address.zip, invoice.invoice_address.city))[:50] }} - {{ invoice.invoice_address.subdivision.name[:20] }} - {{ invoice.invoice_address.country.code3 }} -
- {% endif %} - {% if invoice.party.phone or invoice.party.mobile or invoice.party.fax or invoice.party.website or invoice.party.email %} - - {% if invoice.party.phone or invoice.party.mobile %} - {{ (invoice.party.phone or invoice.party.mobile)[:15] }} - {% endif %} - {% if invoice.party.fax %} - {{ invoice.party.fax[:15] }} - {% endif %} - {% if invoice.party.website %} - {{ invoice.party.website[:60] }} - {% endif %} - {% if invoice.party.email %} - {{ invoice.party.email[:60] }} - {% endif %} - {# Optional: not supported - - - - - #} - + {{ address(invoice.invoice_address) }} + {% if invoice.party.contact_mechanisms %} + {{ contact(invoice.party) }} {% endif %} {% endif %} diff --git a/template_facturae_macros.xml b/template_facturae_macros.xml new file mode 100644 index 0000000..46079de --- /dev/null +++ b/template_facturae_macros.xml @@ -0,0 +1,60 @@ +{% macro administrative_center(centre_code, role_type_code, party) %} + + {{ centre_code }} + {{ role_type_code }} + {% if party.facturae_person_type == 'J' %}{{ party.name and party.name[:40] }}{% else %}{{ party.name and party.name.split(' ', 2)[0][:40] or party.code[:40] }}{% endif %} + {% if party.facturae_person_type == 'F' %} + {{ party.name and party.name.split(' ', 2)[1][:40] }} + {% endif %} + {% if party.facturae_person_type == 'F' and party.name.split(' ') | length > 2 %} + {{ party.name and party.name.split(' ', 2)[2][:40] }} + {% endif %} + {% if party.addresses %}{{ address(party.addresses[0]) }}{% endif %} + {% if party.contact_mechanisms %}{{ contact(party) }}{% endif %} + + + {{ party.name and party.name.split(' ', 2)[0][:40] or party.code[:40] }} + +{% endmacro %} + +{% macro address(address) %} + {% if address.country and address.country.code == 'ES' %} + +
{{ address.street[:80] }}
+ {{ address.zip[:5] }} + {{ address.city[:50] }} + {{ address.subdivision.name[:20] }} + {{ address.country.code3 }} +
+ {% else %} + +
{{ address.street[:80] }}
+ {{ (', '.join(address.zip, address.city))[:50] }} + {{ address.subdivision.name[:20] }} + {{ address.country.code3 }} +
+ {% endif %} +{% endmacro %} + +{% macro contact(party) %} + + {% if party.phone or party.mobile %} + {{ (party.phone or party.mobile)[:15] }} + {% endif %} + {% if party.fax %} + {{ party.fax[:15] }} + {% endif %} + {% if party.website %} + {{ party.website[:60] }} + {% endif %} + {% if party.email %} + {{ party.email[:60] }} + {% endif %} + {# Optional: not supported + + + + + #} + +{% endmacro %} diff --git a/view/party_form.xml b/view/party_form.xml index cff520f..05ac85b 100644 --- a/view/party_form.xml +++ b/view/party_form.xml @@ -8,6 +8,14 @@