ubl_21_zatca.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <odoo>
  3. <data>
  4. <template id="ubl_21_PaymentMeansType_zatca" inherit_id="account_edi_ubl_cii.ubl_20_PaymentMeansType" primary="True">
  5. <xpath expr="//*[local-name()='InstructionID']" position="after">
  6. <cbc:InstructionNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  7. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  8. t-out="vals['adjustment_reason']"/>
  9. </xpath>
  10. </template>
  11. <template id="export_sa_zatca_ubl_extensions">
  12. <ext:UBLExtensions xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  13. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  14. xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
  15. <ext:UBLExtension>
  16. <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
  17. <ext:ExtensionContent>
  18. <sig:UBLDocumentSignatures
  19. xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"
  20. xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"
  21. xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2">
  22. <sac:SignatureInformation>
  23. <cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
  24. <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice
  25. </sbc:ReferencedSignatureID>
  26. <ds:Signature Id="signature" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  27. <ds:SignedInfo>
  28. <ds:CanonicalizationMethod
  29. Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
  30. <ds:SignatureMethod
  31. Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
  32. <ds:Reference Id="invoiceSignedData" URI="">
  33. <ds:Transforms>
  34. <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
  35. <ds:XPath>not(//ancestor-or-self::ext:UBLExtensions)</ds:XPath>
  36. </ds:Transform>
  37. <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
  38. <ds:XPath>not(//ancestor-or-self::cac:Signature)</ds:XPath>
  39. </ds:Transform>
  40. <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
  41. <ds:XPath>
  42. not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])
  43. </ds:XPath>
  44. </ds:Transform>
  45. <ds:Transform Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
  46. </ds:Transforms>
  47. <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
  48. <!-- b64encoded SHA256 digest of document -->
  49. <ds:DigestValue/>
  50. </ds:Reference>
  51. <ds:Reference Type="http://www.w3.org/2000/09/xmldsig#SignatureProperties"
  52. URI="#xadesSignedProperties">
  53. <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
  54. <ds:DigestValue/>
  55. </ds:Reference>
  56. </ds:SignedInfo>
  57. <ds:SignatureValue/>
  58. <ds:KeyInfo>
  59. <ds:X509Data>
  60. <ds:X509Certificate/>
  61. </ds:X509Data>
  62. </ds:KeyInfo>
  63. <ds:Object>
  64. <xades:QualifyingProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#"
  65. Target="signature">
  66. <xades:SignedProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#"
  67. Id="xadesSignedProperties">
  68. <xades:SignedSignatureProperties>
  69. <xades:SigningTime/>
  70. <xades:SigningCertificate>
  71. <xades:Cert>
  72. <xades:CertDigest>
  73. <ds:DigestMethod
  74. xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  75. Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
  76. <ds:DigestValue
  77. xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
  78. </xades:CertDigest>
  79. <xades:IssuerSerial>
  80. <ds:X509IssuerName
  81. xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
  82. <ds:X509SerialNumber
  83. xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
  84. </xades:IssuerSerial>
  85. </xades:Cert>
  86. </xades:SigningCertificate>
  87. </xades:SignedSignatureProperties>
  88. </xades:SignedProperties>
  89. </xades:QualifyingProperties>
  90. </ds:Object>
  91. </ds:Signature>
  92. </sac:SignatureInformation>
  93. </sig:UBLDocumentSignatures>
  94. </ext:ExtensionContent>
  95. </ext:UBLExtension>
  96. </ext:UBLExtensions>
  97. </template>
  98. <template id="export_sa_zatca_ubl_signed_properties">
  99. <xades:SignedProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" Id="xadesSignedProperties">
  100. <xades:SignedSignatureProperties>
  101. <xades:SigningTime t-out="signing_time"/>
  102. <xades:SigningCertificate>
  103. <xades:Cert>
  104. <xades:CertDigest>
  105. <ds:DigestMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  106. Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
  107. <ds:DigestValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  108. t-out="public_key_hashing"/>
  109. </xades:CertDigest>
  110. <xades:IssuerSerial>
  111. <ds:X509IssuerName xmlns:ds="http://www.w3.org/2000/09/xmldsig#" t-out="issuer_name"/>
  112. <ds:X509SerialNumber xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  113. t-out="serial_number"/>
  114. </xades:IssuerSerial>
  115. </xades:Cert>
  116. </xades:SigningCertificate>
  117. </xades:SignedSignatureProperties>
  118. </xades:SignedProperties>
  119. </template>
  120. <template id="ubl_21_InvoiceLineType_zatca" inherit_id="account_edi_ubl_cii.ubl_20_InvoiceLineType" primary="True">
  121. <!-- Remove SellersItemIdentification if None -->
  122. <xpath expr="//*[local-name()='SellersItemIdentification']" position="replace">
  123. <cac:SellersItemIdentification t-if="item_vals['sellers_item_identification_vals']['id']"
  124. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  125. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  126. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  127. <cbc:ID t-out="item_vals['sellers_item_identification_vals']['id']"/>
  128. </cac:SellersItemIdentification>
  129. </xpath>
  130. <xpath expr="//*[local-name()='CreditedQuantity']" position="replace"/>
  131. <xpath expr="//*[local-name()='InvoicedQuantity']" position="replace">
  132. <cbc:InvoicedQuantity
  133. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  134. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  135. t-att="vals.get('invoiced_quantity_attrs', {})"
  136. t-out="vals['invoiced_quantity']"/>
  137. </xpath>
  138. <xpath expr="//*[local-name()='LineExtensionAmount']" position="after">
  139. <cac:DocumentReference
  140. t-if="vals.get('prepayment_vals', {})"
  141. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  142. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  143. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  144. <cbc:ID t-out="vals['prepayment_vals']['prepayment_id']"/>
  145. <cbc:IssueDate t-esc="vals['prepayment_vals']['issue_date'].strftime('%Y-%m-%d')"/>
  146. <cbc:IssueTime t-esc="vals['prepayment_vals']['issue_date'].strftime('%H:%M:%S')"/>
  147. <cbc:DocumentTypeCode t-out="vals['prepayment_vals']['document_type_code']"/>
  148. </cac:DocumentReference>
  149. </xpath>
  150. </template>
  151. <template id="ubl_21_TaxTotalType_zatca" inherit_id="account_edi_ubl_cii.ubl_20_TaxTotalType" primary="True">
  152. <xpath expr="//*[local-name()='TaxAmount']" position="after">
  153. <cbc:RoundingAmount xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  154. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  155. t-att-currencyID="vals['currency'].name"
  156. t-esc="format_float(vals.get('total_amount_sa'), vals['currency_dp'])"/>
  157. </xpath>
  158. </template>
  159. <template id="ubl_21_PartyType_zatca" inherit_id="account_edi_ubl_cii.ubl_20_PartyType" primary="True">
  160. <xpath expr="//*[local-name()='PartyIdentification']" position="replace">
  161. <cac:PartyIdentification t-if="party_vals.get('id')"
  162. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  163. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  164. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  165. <cbc:ID t-att="party_vals.get('id_attrs', {})" t-out="party_vals['id']"/>
  166. </cac:PartyIdentification>
  167. </xpath>
  168. </template>
  169. <template id="ubl_21_AddressType_zatca" inherit_id="account_edi_ubl_cii.ubl_20_AddressType" primary="True">
  170. <!-- AdditionalStreetName causes the Validation SDK to crash, so it has to be removed -->
  171. <xpath expr="//*[local-name()='AdditionalStreetName']" position="replace"/>
  172. <xpath expr="//*[local-name()='StreetName']" position="after">
  173. <t xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  174. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  175. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  176. <!-- Add Building number in compliance with rules KSA-17 (seller)/ KSA-18 (customer) -->
  177. <cbc:BuildingNumber t-out="vals.get('building_number')"/>
  178. <!-- Add Plot identification in compliance with rules KSA-23 (seller)/ KSA-19 (customer) -->
  179. <cbc:PlotIdentification t-out="vals.get('plot_identification')"/>
  180. <!-- Add Neighborhood in compliance with rules KSA-3 (seller)/ KSA-4 (customer) -->
  181. <cbc:CitySubdivisionName t-out="vals.get('neighborhood')"/>
  182. </t>
  183. </xpath>
  184. </template>
  185. <template id="ubl_21_InvoiceType_zatca" inherit_id="account_edi_ubl_cii.ubl_21_InvoiceType" primary="True">
  186. <!-- For ZATCA, we do not use CreditNoteTypeCode or DebitNoteTypeCode tags. We always use InvoiceTypeCode. -->
  187. <xpath expr="//*[local-name()='CreditNoteTypeCode']" position="replace"/>
  188. <xpath expr="//*[local-name()='InvoiceTypeCode']" position="replace">
  189. <cbc:InvoiceTypeCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  190. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  191. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  192. t-att="vals['invoice_type_code_attrs']"
  193. t-out="vals['invoice_type_code']"/>
  194. </xpath>
  195. <!-- For ZATCA, we do not use CreditNoteLine or DebitNoteLine tags. We always use InvoiceLine. -->
  196. <xpath expr="//*[local-name()='CreditNoteLine']" position="replace"/>
  197. <xpath expr="//*[local-name()='InvoiceLine']" position="replace">
  198. <cac:InvoiceLine xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  199. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  200. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  201. <t t-call="{{InvoiceLineType_template}}">
  202. <t t-set="vals" t-value="foreach_vals"/>
  203. </t>
  204. </cac:InvoiceLine>
  205. </xpath>
  206. <!-- Remove Order Reference if None -->
  207. <xpath expr="//*[local-name()='OrderReference']" position="replace">
  208. <cac:OrderReference t-if="vals.get('order_reference')"
  209. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  210. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  211. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  212. <cbc:ID t-out="vals['order_reference']"/>
  213. </cac:OrderReference>
  214. </xpath>
  215. <!-- Add Invoice UUID in compliance with rule BR-KSA-03 -->
  216. <xpath expr="//*[local-name()='ID']" position="after">
  217. <cbc:UUID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  218. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  219. t-esc="invoice.l10n_sa_uuid"/>
  220. </xpath>
  221. <!-- Add Invoice Issue Time in compliance with rule KSA-25 -->
  222. <xpath expr="//*[local-name()='IssueDate']" position="replace">
  223. <t xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  224. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  225. <cbc:IssueDate t-esc="vals['issue_date'].strftime('%Y-%m-%d')"/>
  226. <cbc:IssueTime t-esc="vals['issue_date'].strftime('%H:%M:%S')"/>
  227. </t>
  228. </xpath>
  229. <!-- Add Tax Currency Code in compliance with rules BR-KSA-EN16931-02 and BR-KSA-68 -->
  230. <xpath expr="//*[local-name()='DocumentCurrencyCode']" position="after">
  231. <cbc:TaxCurrencyCode xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  232. xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  233. t-esc="invoice.company_currency_id.name"/>
  234. </xpath>
  235. <!-- Add Previous Invoice Hash & Invoice Counter Value -->
  236. <xpath expr="//*[local-name()='BillingReference']" position="after">
  237. <t xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  238. xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  239. xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
  240. <!-- Add QR Code in compliance with rule BR-KSA-27 -->
  241. <cac:AdditionalDocumentReference t-if="invoice._l10n_sa_is_simplified()">
  242. <cbc:ID>QR</cbc:ID>
  243. <cac:Attachment>
  244. <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">N/A</cbc:EmbeddedDocumentBinaryObject>
  245. </cac:Attachment>
  246. </cac:AdditionalDocumentReference>
  247. <!-- Add Previous Invoice Hash in compliance with rule BR-KSA-61 -->
  248. <cac:AdditionalDocumentReference>
  249. <cbc:ID>PIH</cbc:ID>
  250. <cac:Attachment>
  251. <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain"
  252. t-out="vals['previous_invoice_hash']"/>
  253. </cac:Attachment>
  254. </cac:AdditionalDocumentReference>
  255. <!-- Add Invoice Counter Value in compliance with rules BR-KSA-33 and BR-KSA-34 -->
  256. <cac:AdditionalDocumentReference>
  257. <cbc:ID>ICV</cbc:ID>
  258. <cbc:UUID t-out="invoice.l10n_sa_chain_index"/>
  259. </cac:AdditionalDocumentReference>
  260. <!-- Add Signature references in compliance with rules BR-KSA-29 and BR-KSA-30 -->
  261. <cac:Signature t-if="invoice._l10n_sa_is_simplified()">
  262. <cbc:ID>urn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
  263. <cbc:SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
  264. </cac:Signature>
  265. </t>
  266. </xpath>
  267. </template>
  268. </data>
  269. </odoo>