| 1 |
|
| 2 |
from odoo import models, _ |
| 3 |
from odoo.tools import float_is_zero |
| 4 |
|
| 5 |
ANZ_TAX_CATEGORIES = {'S', 'E', 'Z', 'G', 'O'} |
| 6 |
|
| 7 |
|
| 8 |
class AccountEdiXmlPint_Anz(models.AbstractModel): |
| 9 |
_name = 'account.edi.xml.pint_anz' |
| 10 |
_inherit = ["account.edi.xml.ubl_bis3"] |
| 11 |
_description = "Australia & New Zealand implementation of Peppol International (PINT) model for Billing" |
| 12 |
""" |
| 13 |
Pint is a standard for International Billing from Peppol. It is based on Peppol BIS Billing 3. |
| 14 |
It serves as a base for per-country specialization, while keeping a standard core for data being used |
| 15 |
across countries. This is not meant to be used directly, but rather to be extended by country-specific modules. |
| 16 |
|
| 17 |
The ANZ PINT format is the Australia & New Zealand implementation of PINT. |
| 18 |
|
| 19 |
* PINT Official documentation: https://docs.peppol.eu/poac/pint/pint/ |
| 20 |
* PINT ANZ Official documentation: https://docs.peppol.eu/poac/aunz/pint-aunz/ |
| 21 |
""" |
| 22 |
|
| 23 |
def _export_invoice_filename(self, invoice): |
| 24 |
|
| 25 |
return f"{invoice.name.replace('/', '_')}_pint_anz.xml" |
| 26 |
|
| 27 |
def _get_customization_id(self, process_type='billing'): |
| 28 |
if process_type == 'billing': |
| 29 |
return 'urn:peppol:pint:billing-1@aunz-1' |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
def _ubl_default_tax_category_grouping_key(self, base_line, tax_data, vals, currency): |
| 36 |
|
| 37 |
grouping_key = super()._ubl_default_tax_category_grouping_key(base_line, tax_data, vals, currency) |
| 38 |
if not grouping_key: |
| 39 |
return |
| 40 |
|
| 41 |
grouping_key['scheme_id'] = 'GST' |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
supplier = vals['supplier'] |
| 47 |
if not supplier.ref_company_ids[:1].l10n_au_is_gst_registered: |
| 48 |
grouping_key['tax_category_code'] = 'O' |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if ( |
| 53 |
grouping_key['tax_category_code'] == 'O' |
| 54 |
and not grouping_key['percent'] |
| 55 |
): |
| 56 |
grouping_key['percent'] = None |
| 57 |
|
| 58 |
return grouping_key |
| 59 |
|
| 60 |
def _add_invoice_header_nodes(self, document_node, vals): |
| 61 |
|
| 62 |
super()._add_invoice_header_nodes(document_node, vals) |
| 63 |
|
| 64 |
|
| 65 |
document_node['cbc:ProfileID'] = {'_text': 'urn:peppol:bis:billing'} |
| 66 |
|
| 67 |
def _get_party_node(self, vals): |
| 68 |
|
| 69 |
party_node = super()._get_party_node(vals) |
| 70 |
commercial_partner = vals['partner'].commercial_partner_id |
| 71 |
|
| 72 |
party_node['cac:PartyTaxScheme'][0]['cac:TaxScheme']['cbc:ID']['_text'] = 'GST' |
| 73 |
|
| 74 |
|
| 75 |
if commercial_partner.country_code in ('AU', 'NZ'): |
| 76 |
party_node['cac:PartyLegalEntity']['cbc:CompanyID']['schemeID'] = commercial_partner.peppol_eas |
| 77 |
|
| 78 |
return party_node |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
def _export_invoice_constraints(self, invoice, vals): |
| 85 |
|
| 86 |
constraints = super()._export_invoice_constraints(invoice, vals) |
| 87 |
|
| 88 |
|
| 89 |
tax_total_node = vals['document_node']['cac:TaxTotal'][0] |
| 90 |
for tax_subtotal_node in tax_total_node['cac:TaxSubtotal']: |
| 91 |
if any(tax_category_node['cbc:ID']['_text'] not in ANZ_TAX_CATEGORIES for tax_category_node in tax_subtotal_node['cac:TaxCategory']): |
| 92 |
constraints['anz_vat_category_required'] = _("You must set a tax category on each taxes of the invoice.\nValid categories are: S, E, Z, G, O") |
| 93 |
|
| 94 |
|
| 95 |
count_outside_of_scope_breakdown = 0 |
| 96 |
for tax_subtotal in tax_total_node['cac:TaxSubtotal']: |
| 97 |
if any(tax_category_node['cbc:ID']['_text'] != 'O' for tax_category_node in tax_subtotal['cac:TaxCategory']): |
| 98 |
continue |
| 99 |
count_outside_of_scope_breakdown += 1 |
| 100 |
|
| 101 |
if float_is_zero(tax_subtotal['cbc:TaxAmount']['_text'], precision_digits=2): |
| 102 |
continue |
| 103 |
|
| 104 |
if vals['supplier'].ref_company_ids[:1].l10n_au_is_gst_registered: |
| 105 |
constraints['anz_tax_breakdown_amount'] = \ |
| 106 |
self.env._("A tax category of type 'Not subject to tax' must have tax" |
| 107 |
" amount set to 0") |
| 108 |
else: |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
constraints['anz_non_gst_supplier_tax_scope'] = \ |
| 117 |
self.env._("Suppliers not registered for GST cannot use taxes that are" |
| 118 |
" not zero-rated. Please ensure the tax category is set to" |
| 119 |
" 'O' (Services outside scope of tax) with a tax amount of 0.") |
| 120 |
|
| 121 |
|
| 122 |
if count_outside_of_scope_breakdown > 1 and vals['supplier'].ref_company_ids[:1].l10n_au_is_gst_registered: |
| 123 |
constraints['anz_duplicate_tax_breakdown'] = \ |
| 124 |
self.env._("A tax breakdown of type 'Not subject to tax' should appear at most" |
| 125 |
" once in the tax breakdown") |
| 126 |
|
| 127 |
|
| 128 |
for partner_type in ('supplier', 'customer'): |
| 129 |
partner = vals[partner_type] |
| 130 |
if partner.country_code == 'AU' and partner.peppol_eas != '0151': |
| 131 |
constraints[f'au_{partner_type}_eas_0151'] = _("The Peppol EAS must be set to ABN (0151) if the partner country is Australia.") |
| 132 |
elif partner.country_code == 'NZ' and partner.peppol_eas != '0088': |
| 133 |
constraints[f'nz_{partner_type}_eas_0088'] = _("The Peppol EAS must be set to EAN (0088) if the partner country is New Zealand.") |
| 134 |
|
| 135 |
return constraints |