Skip to content

Commit

Permalink
[IMP] account_invoice_import_invoice2data: Add AzureInterior Test
Browse files Browse the repository at this point in the history
This commit adds an test/example of all the invoice fields which can be imported.
  • Loading branch information
bosd committed Oct 7, 2023
1 parent 489ddfd commit 9460b2b
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
41 changes: 41 additions & 0 deletions account_invoice_import_invoice2data/demo/demo_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,46 @@
<field name="static_product_id" ref="internet_access" />
</record>

<record id="product_beeswax_xl" model="product.product">
<field name="name">Beeswax XL</field>
<field name="description_sale">Acme beeswax</field>
<field name="default_code">17589684</field>
<field name="list_price">42</field>
<field name="type">consu</field>
<field name="uom_id" ref="uom.product_uom_kgm" />
<field name="uom_po_id" ref="uom.product_uom_kgm" />
</record>

<record id="olive_oil" model="product.product">
<field name="name">Olive Oil</field>
<field name="categ_id" ref="product.product_category_1" />
<field name="sale_ok" eval="True" />
<field name="purchase_ok" eval="True" />
<field name="type">consu</field>
<field name="uom_id" ref="uom.product_uom_litre" />
<field name="uom_po_id" ref="uom.product_uom_litre" />
<field name="barcode">987123</field>
</record>

<record id="luxury_truffles" model="product.product">
<field name="name">Luxury Truffles</field>
<field name="categ_id" ref="product.product_category_1" />
<field name="sale_ok" eval="True" />
<field name="purchase_ok" eval="True" />
<field name="type">consu</field>
<field name="uom_id" ref="uom.product_uom_gram" />
<field name="uom_po_id" ref="uom.product_uom_gram" />
<field name="default_code">LUX_TRF</field>
<!-- <field
name="supplier_taxes_id"
eval="[(3, 0, [ref('l10n_generic_coa.1_purchase_tax_template')])]"
/> -->
</record>

<record id="azure_import_config" model="account.invoice.import.config">
<field name="name">Azure Interior Multiline Auto Product</field>
<field name="partner_id" ref="base.res_partner_12" />
<field name="invoice_line_method">nline_auto_product</field>
</record>

</odoo>
Binary file not shown.
95 changes: 95 additions & 0 deletions account_invoice_import_invoice2data/tests/test_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,98 @@ def test_import_free_invoice(self):
self.assertEqual(len(invoices), 1)
inv = invoices[0]
self.assertEqual(fields.Date.to_string(inv.invoice_date), "2015-07-02")

def test_import_azure_interior_invoice(self):
"""Function for testing almost all supported fields"""
filename = "AzureInterior.pdf"
invoice_file = file_open(
"account_invoice_import_invoice2data/tests/pdf/" + filename, "rb"
)
pdf_file = invoice_file.read()
pdf_file_b64 = base64.b64encode(pdf_file)
wiz = self.env["account.invoice.import"].create(
{
"invoice_file": pdf_file_b64,
"invoice_filename": filename,
}
)
invoice_file.close()
wiz.import_invoice()
# create_invoice_action_button
wiz.create_invoice_action(origin="BOSD Import Vendor Bill wizard")
# Check result of invoice creation
invoices = self.env["account.move"].search(
[
("state", "=", "draft"),
# ("move_type", "=", "in_invoice"),
# ("ref", "=", "INV/2023/03/0008"),
("ref", "ilike", "INV"),
]
)
self.assertEqual(len(invoices), 1)
inv = invoices[0]
self.assertEqual(inv.move_type, "in_invoice")
self.assertEqual(fields.Date.to_string(inv.invoice_date), "2023-03-20")
self.assertEqual(inv.partner_id, self.env.ref("base.res_partner_12"))
self.assertEqual(inv.journal_id.type, "purchase")
self.assertEqual(float_compare(inv.amount_total, 279.84, precision_digits=2), 0)
self.assertEqual(
float_compare(inv.amount_untaxed, 262.9, precision_digits=2), 0
)

self.assertEqual(
inv.narration,
"Due to global inflation our payment term has changed to 15 days.",
)

# Following tests are disabled. Not yet implemented in account_invoice_import
# self.assertEqual(inv.journal_id.payment_reference, "202309097001")
# self.assertEqual(inv.journal_id.incoterm_id, self.env.ref("account.incoterm_DPU")

self.assertEqual(len(inv.invoice_line_ids), 8)
iline = inv.invoice_line_ids[0]
self.assertEqual(iline.name, "--- Non Food ---")
self.assertEqual(iline.display_type, "line_section")
iline = inv.invoice_line_ids[1]
self.assertEqual(iline.name, "Beeswax XL\nAcme beeswax")
self.assertEqual(
iline.product_id,
self.env.ref("account_invoice_import_invoice2data.product_beeswax_xl"),
)
self.assertEqual(float_compare(iline.quantity, 1.0, precision_digits=0), 0)
self.assertEqual(float_compare(iline.price_unit, 42.00, precision_digits=2), 0)

iline = inv.invoice_line_ids[2]
self.assertEqual(iline.name, "Office Chair")
self.assertEqual(
iline.product_id,
self.env.ref("product.product_delivery_01"),
)
self.assertEqual(float_compare(iline.quantity, 1.0, precision_digits=0), 0)
self.assertEqual(float_compare(iline.price_unit, 70.00, precision_digits=2), 0)

iline = inv.invoice_line_ids[3]
self.assertEqual(iline.name, "--- Food Products ---")
self.assertEqual(iline.display_type, "line_section")
iline = inv.invoice_line_ids[4]
self.assertEqual(iline.name, "Olive Oil")
self.assertEqual(
iline.product_id,
self.env.ref("account_invoice_import_invoice2data.olive_oil"),
)
# todo test discount, not yet implemented in account_invoice_import
self.assertEqual(float_compare(iline.quantity, 1.0, precision_digits=0), 0)
self.assertEqual(float_compare(iline.price_unit, 1.00, precision_digits=2), 0)
iline = inv.invoice_line_ids[5]
self.assertEqual(
iline.name, "Our Olive Oil is delivered in a re-usable glass container"
)
self.assertEqual(iline.display_type, "line_note")
iline = inv.invoice_line_ids[6]
self.assertEqual(iline.name, "Luxury Truffles")
self.assertEqual(
iline.product_id,
self.env.ref("account_invoice_import_invoice2data.luxury_truffles"),
)
self.assertEqual(float_compare(iline.quantity, 15.0, precision_digits=0), 0)
self.assertEqual(float_compare(iline.price_unit, 10.00, precision_digits=2), 0)

0 comments on commit 9460b2b

Please sign in to comment.