-
- create Company
+ In order to test the EDI export features of Invoices
-
- !record {model: res.company, id: res_company_test}:
- name: Thomson pvt. ltd.
- partner_id: 1
- rml_header: 1
- rml_header2: 1
- rml_header3: 1
- currency_id: 1
-
--
- create customer
+ First I create a draft customer invoice
-
- !record {model: res.partner, id: res_partner_test}:
- name: Junjun wala
- supplier: False
- company_id: res_company_test
- address:
- - partner_id: res_partner_test
- type: default
- name: ivan
- street: m g road
- street2: line 28
- city: paris
-
--
- Creating a customer invoice record
--
- !record {model: account.invoice, id: account_invoice_test}:
- amount_tax: 0.0
- amount_total: 83.0
- amount_untaxed: 83.0
+ !record {model: account.invoice, id: invoice_edi_1}:
+ journal_id: 1
+ partner_id: base.res_partner_agrolait
currency_id: base.EUR
- date_invoice: '2011-06-22'
+ company_id: 1
+ account_id: account.a_pay
+ date_invoice: !eval "'%s' % (time.strftime('%Y-%m-%d'))"
+ name: selling product
+ type: 'out_invoice'
invoice_line:
- name: '[CPU1] Processor AMD Athlon XP 1800+'
- partner_id: res_partner_test
- price_subtotal: 75.0
- price_unit: 75.0
- product_id: product.product_product_cpu1
+ - product_id: product.product_product_pc1
+ uos_id: 1
quantity: 1.0
- journal_id: 'False'
- name: Nothing
- partner_id: res_partner_test
- payment_term: account.account_payment_term
- reference_type: none
-
+ price_unit: 10.0
+ name: 'basic pc'
+ account_id: account.a_pay
+ invoice_line:
+ - product_id: product.product_product_pc3
+ uos_id: 1
+ quantity: 5.0
+ price_unit: 100.0
+ name: 'Medium PC'
+ account_id: account.a_pay
+ tax_line:
+ - name: sale tax
+ account_id: account.a_pay
+ manual: True
+ amount: 1000.00
+-
+ I confirm and open the invoice
-
- Tesing of Export functionality and Import Functionality
+ !workflow {model: account.invoice, ref: invoice_edi_1, action: invoice_open}
-
- !python {model: ir.edi.document}: |
-
- invoice_obj = self.pool.get('account.invoice')
- invoice_ids = invoice_obj.search(cr, uid, [partner_id])
- if invoice_ids:
- invoices = invoice_obj.browse(cr, uid, invoice_ids)
- tokens = self.export_edi(cr, uid, invoices)
- for token in tokens:
- document = self.get_document(cr, uid, token, context=context)
- a = self.import_edi(cr, uid, edi_document = document)
-
+ Then I export the customer invoice
-
- Check after import of document customer become supplier or not
+ !python {model: edi.document}: |
+ invoice_pool = self.pool.get('account.invoice')
+ invoice = invoice_pool.browse(cr, uid, ref("invoice_edi_1"))
+ token = self.export_edi(cr, uid, [invoice])
+ assert token, 'Invalid EDI Token'
+-
+ Then I import a sample EDI document of another customer invoice
-
!python {model: account.invoice}: |
- ids=self.search(cr, uid, [('partner_id','=',base.main_company),('company_id','=',res_company_test),('type','=','in_invoice')])
- if not ids:
- raise AssertionError("Invoice is not imported")
-
-
\ No newline at end of file
+ import time
+ edi_document = {
+ "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.random_invoice_763jsms",
+ "__module": "account",
+ "__model": "account.invoice",
+ "__version": [6,1,0],
+ "internal_number": time.strftime("SAJ/%Y/002"),
+ "company_address": {
+ "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.main_address",
+ "__module": "base",
+ "__model": "res.partner",
+ "city": "Gerompont",
+ "zip": "1367",
+ "country_id": ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.be", "Belgium"],
+ "phone": "(+32).81.81.37.00",
+ "street": "Chaussee de Namur 40",
+ "bank_ids": [
+ ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_bank-ZrTWzesfsdDJzGbp","Sample bank: 123465789-156113"]
+ ],
+ },
+ "company_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_company_test11", "Thomson pvt. ltd."],
+ "currency": {
+ "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.EUR",
+ "__module": "base",
+ "__model": "res.currency",
+ "code": "EUR",
+ "symbol": "€",
+ },
+ "partner_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_test20", "Junjun wala"],
+ "partner_address": {
+ "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.res_partner_address_7wdsjasdjh",
+ "__module": "base",
+ "__model": "res.partner",
+ "phone": "(+32).81.81.37.00",
+ "street": "Chaussee de Namur 40",
+ "city": "Gerompont",
+ "zip": "1367",
+ "country_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.be", "Belgium"],
+ },
+ "date_invoice": time.strftime('%Y-%m-%d'),
+ "name": "sample invoice",
+ "tax_line": [{
+ "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_tax-4g4EutbiEMVl",
+ "__module": "account",
+ "__model": "account.invoice.tax",
+ "amount": 1000.0,
+ "manual": True,
+ "name": "sale tax",
+ }],
+ "type": "out_invoice",
+ "invoice_line": [{
+ "__module": "account",
+ "__model": "account.invoice.line",
+ "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_line-1RP3so",
+ "uos_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_uom_unit", "PCE"],
+ "name": "Basic PC",
+ "price_unit": 10.0,
+ "product_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_product_pc1", "[PC1] Basic PC"],
+ "quantity": 1.0
+ },
+ {
+ "__module": "account",
+ "__model": "account.invoice.line",
+ "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_line-u2XV5",
+ "uos_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_uom_unit", "PCE"],
+ "name": "Medium PC",
+ "price_unit": 100.0,
+ "product_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_product_pc3", "[PC3] Medium PC"],
+ "quantity": 5.0
+ }]
+ }
+ invoice_id = self.edi_import(cr, uid, edi_document, context=context)
+ assert invoice_id, 'EDI import failed'
+ invoice_new = self.browse(cr, uid, invoice_id)
+
+ # check bank info on partner
+ assert len(invoice_new.partner_id.bank_ids) == 1, "Expected 1 bank entry related to partner"
+ bank_info = invoice_new.partner_id.bank_ids[0]
+ assert bank_info.acc_number == "Sample bank: 123465789-156113", 'Expected "Sample bank: 123465789-156113", got %s' % bank_info.acc_number
+
+ assert invoice_new.partner_id.supplier, 'Imported Partner is not marked as supplier'
+ assert invoice_new.reference == time.strftime("SAJ/%Y/002"), "internal number is not stored in reference"
+ assert invoice_new.reference_type == 'none', "reference type is not set to 'none'"
+ assert invoice_new.internal_number == False, "internal number is not reset"
+ assert invoice_new.journal_id.id, "journal id is not selected"
+ assert invoice_new.type == 'in_invoice', "Invoice type was not set properly"
+ assert len(invoice_new.invoice_line) == 2, "invoice lines are not same"
+ for inv_line in invoice_new.invoice_line:
+ if inv_line.name == 'Basic PC':
+ assert inv_line.uos_id.name == "PCE" , "uom is not same"
+ assert inv_line.price_unit == 10 , "price unit is not same"
+ assert inv_line.quantity == 1 , "product qty is not same"
+ assert inv_line.price_subtotal == 10, "price sub total is not same"
+ elif inv_line.name == 'Medium PC':
+ assert inv_line.uos_id.name == "PCE" , "uom is not same"
+ assert inv_line.price_unit == 100 , "price unit is not same"
+ assert inv_line.quantity == 5 , "product qty is not same"
+ assert inv_line.price_subtotal == 500, "price sub total is not same"
+ else:
+ raise AssertionError('unknown invoice line: %s' % inv_line)
+ for inv_tax in invoice_new.tax_line:
+ assert inv_tax.manual, "tax line not set to manual"
+ assert inv_tax.account_id, "missing tax line account"