Debian Codegraph @

addons/purchase_edi_ubl_bis3/tests/test_purchase_order_edi_gen.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2 from odoo.addons.account.tests.common import AccountTestInvoicingCommon
3 from odoo.tests import tagged
4 from odoo.tools import file_open
5
6 from lxml import etree
7 from datetime import datetime
8
9
10 @tagged('post_install', '-at_install')
11 class TestPurchaseOrderEDIGen(AccountTestInvoicingCommon):
12 def test_purchase_order_download_edi(self):
13 self.env.company.vat = 'BE0477472701'
14 self.partner_a.vat = 'NL123456782B90'
15
16 po = self.env['purchase.order'].create({
17 'name': 'My PO',
18 'partner_id': self.partner_a.id,
19 'partner_ref': 'SO/1234',
20 'order_line': [
21 (0, 0, {
22 'product_id': self.product_a.id,
23 'name': 'Product A description',
24 'product_qty': 10.0,
25 'price_unit': 50.0,
26 'discount': 10.0,
27 }),
28 (0, 0, {
29 'product_id': self.product_a.id,
30 'name': 'Product A description',
31 'product_qty': 1.0,
32 'price_unit': 10.0,
33 }),
34 ],
35 })
36
37 po.button_confirm()
38
39 file_content = self.env['purchase.edi.xml.ubl_bis3']._export_order(po)
40 generated_xml = etree.fromstring(file_content)
41
42 with file_open('purchase_edi_ubl_bis3/tests/data/test_po_edi.xml', 'r') as f:
43 current_date = f'{datetime.today().date()}'
44 xml_template = f.read().encode().replace(b'create_date_placeholder', current_date.encode())
45 expected_xml = etree.fromstring(xml_template)
46 self.assertXmlTreeEqual(generated_xml, expected_xml)