[IMP] improved yml for edi sale,purchase and account invoice
[odoo/odoo.git] / addons / account / test / test_edi_invoice.yml
1 -
2   I create a company for Customer
3 -
4   !record {model: res.company, id: res_company_test11}:
5     name: Thomson pvt. ltd.
6     partner_id: 1
7     rml_header: 1
8     rml_header2: 1
9     rml_header3: 1
10     currency_id: 1
11
12 -
13   I create a partner which is a my customer
14 -
15   !record {model: res.partner, id: res_partner_test20}:
16     name: Junjun wala
17     supplier: False
18     company_id: res_company_test11
19     opt_out: True
20 -
21   I create one customer invoice
22 -
23   !record {model: account.invoice, id: customer_invoice_test}:
24     journal_id: 1
25     partner_id: res_partner_test20
26     currency_id: base.EUR
27     address_invoice_id: base.res_partner_address_11
28     company_id: res_company_test11
29     account_id: account.a_pay
30     date_invoice: '2011-06-22'
31     name: selling product
32     type: 'out_invoice'
33     invoice_line:
34       - product_id: product.product_product_pc1
35         partner_id: res_partner_test20
36         uos_id: 1
37         quantity: 1.0
38         price_unit: 10.0
39         name: 'basic pc'
40         account_id: account.a_pay
41     invoice_line:
42       - product_id: product.product_product_pc3
43         partner_id: res_partner_test20
44         uos_id: 1
45         quantity: 5.0
46         price_unit: 100.0
47         name: 'Medium PC'
48         account_id: account.a_pay
49         
50     tax_line:
51       - name: sale tax
52         account_id: account.a_pay
53         manual: True
54         amount: 1000.00
55
56 -
57   I Open the Invoice
58 -
59   !python {model: account.invoice}: |
60     
61     invoices = self.browse(cr, uid, ref("customer_invoice_test"))
62     import netsvc
63     wf_service = netsvc.LocalService("workflow")
64     wf_service.trg_validate(uid, 'account.invoice',invoices.id,'invoice_open', cr)
65
66 -
67   I Testing of EDI functionality. First I export customer invoice from my company than import that invoice into customer company
68 -
69   !python {model: ir.edi.document}: |
70     invoice_pool = self.pool.get('account.invoice')
71     invoice = invoice_pool.browse(cr, uid, ref("customer_invoice_test"))
72
73     tokens = self.export_edi(cr, uid, [invoice])
74     assert tokens, 'Token is not generated'
75 -
76   I import of EDI document of custmer invoice
77 -
78   !python {model: ir.edi.document}: |
79     invoice_pool = self.pool.get('account.invoice')
80     edi_document = {
81         "internal_number": "SAJ/2011/002", 
82         "company_address": {
83                 "city": "Gerompont", 
84                 "zip": "1367", 
85                 "__last_update": False, 
86                 "country_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:base.be", "Belgium"], 
87                 "__id": "b22acf7a-ddcd-11e0-a4db-701a04e25543:base.main_address", 
88                 "phone": "(+32).81.81.37.00", 
89                 "street": "Chaussee de Namur 40"
90         }, 
91         "company_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:account.res_company_test11", "Thomson pvt. ltd."], 
92         "currency_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:base.EUR", "EUR (\u20ac)"], 
93         "address_invoice_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:base.res_partner_address_11", "Sebastien LANGE, France, Alencon, 1 place de l'\u00c9glise"],
94         "partner_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:account.res_partner_test20", "Junjun wala"], 
95         "__attachments": [], 
96         "__module": "account", 
97         "amount_total": 1010.0, 
98         "date_invoice": "2011-06-22", 
99         "amount_untaxed": 10.0, 
100         "name": "selling product", 
101         "__model": "account.invoice", 
102         "__last_update": False, 
103         "tax_line": [{
104                 "amount": 1000.0, 
105                 "manual": True, 
106                 "__id": "b22acf7a-ddcd-11e0-a4db-701a04e25543:b22acf7a-ddcd-11e0-a4db-701a04e25543:account.account_invoice_tax-4g4EutbiEMVl", 
107                 "name": "sale tax", 
108                 "__last_update": False
109         }], 
110         "__id": "b22acf7a-ddcd-11e0-a4db-701a04e25543:account.customer_invoice_test", 
111         "amount_tax": 1000.0, 
112         "__version": [6, 1], 
113         "type": "out_invoice", 
114         "invoice_line": [{
115                 "uos_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:product.product_uom_unit", "PCE"], 
116                 "name": "basic pc", 
117                 "__last_update": False, 
118                 "price_unit": 10.0, 
119                 "price_subtotal": 10.0, 
120                 "__id": "b22acf7a-ddcd-11e0-a4db-701a04e25543:b22acf7a-ddcd-11e0-a4db-701a04e25543:account.account_invoice_line-1RP3so-u2vV4",
121                 "product_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:product.product_product_pc1", "[PC1] Basic PC"], 
122                 "quantity": 1.0
123         },
124         {
125                 "uos_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:product.product_uom_unit", "PCE"], 
126                 "name": "Medim PC", 
127                 "__last_update": False, 
128                 "price_unit": 100.0, 
129                 "price_subtotal": 100.0, 
130                 "__id": "b22acf7a-ddcd-11e0-a4db-701a04e25543:b22acf7a-ddcd-11e0-a4db-701a04e25543:account.account_invoice_line-1RP3so-u2vV4",
131                 "product_id": ["b22acf7a-ddcd-11e0-a4db-701a04e25543:product.product_product_pc3", "[PC3] Medium PC"], 
132                 "quantity": 5.0
133         }]
134     }
135
136     invoice_id = invoice_pool.edi_import(cr, uid, edi_document, context=context)
137     invoice_new = invoice_pool.browse(cr, uid, invoice_id, context=context)
138     assert invoice_id, 'Invoice is not imported'
139 -
140   I Checking the out invoice become in invoice or not after import 
141 -
142   !python {model: account.invoice}: |
143     
144     new_partner_id = self.pool.get('res.partner').name_search(cr, uid, "Thomson pvt. ltd.")
145     assert new_partner_id, 'Partner is not created of Supplier'
146     ids = self.search(cr, uid, [('partner_id','=',new_partner_id[0][0]),('reference','=',"SAJ/2011/002")])
147     assert ids, 'Invoice does not have created of party'
148     invoice_new = self.browse(cr, uid, ids[0])
149     assert invoice_new.reference == "SAJ/2011/002", "internal number is not stored in reference"
150     assert invoice_new.reference_type == 'none', "reference type is not set to 'None'"
151     assert invoice_new.internal_number == False, "internal number is not reset"
152     assert invoice_new.journal_id.id, "journal id is not selected"
153     assert invoice_new.type == 'in_invoice', "Imported in voice is not supplier invoice"
154     assert invoice_new.amount_total == 1010.0, "Amount total is not same"
155     assert invoice_new.amount_tax == 1000.0, "Amount tax is not same"
156     assert invoice_new.amount_untaxes == 10.0, "Amount untaxed is not same"
157     product = ['Medium PC','Basic PC']
158     for inv_line in invoice_new.invoice_line:
159         assert inv_line.account_id.id, "account_id is not taken from product's default"
160         assert inv_line.product_id.name in ['Medium PC','Basic PC'], "product  is not in Invoice line"
161     for inv_tax in invoice_new.tax_line:
162         assert inv_tax.manual, "for tax line manual is not set to True"
163         assert inv_tax.account_id, "for tax_line default accounts is not picked based on the tax config of the DB where it is imported."