[MERGE] Forward-port of latest saas-1 bugfixes, up to rev. 8793 rev-id: dle@openerp...
[odoo/odoo.git] / addons / account / test / test_edi_invoice.yml
1 -
2   In order to test the EDI export features of Invoices
3 -
4   First I create a draft customer invoice
5 -
6   !record {model: account.invoice, id: invoice_edi_1}:
7     journal_id: 1
8     partner_id: base.res_partner_2
9     currency_id: base.EUR
10     company_id: 1
11     account_id: account.a_pay
12     date_invoice: !eval "'%s' % (time.strftime('%Y-%m-%d'))"
13     name: selling product
14     type: 'out_invoice'
15     invoice_line:
16       - product_id: product.product_product_3
17         uos_id: 1
18         quantity: 1.0
19         price_unit: 10.0
20         name: 'basic pc'
21         account_id: account.a_pay
22     invoice_line:
23       - product_id: product.product_product_5
24         uos_id: 1
25         quantity: 5.0
26         price_unit: 100.0
27         name: 'PC on Demand'
28         account_id: account.a_pay
29     tax_line:
30       - name: sale tax
31         account_id: account.a_pay
32         manual: True
33         amount: 1000.00
34 -
35   I confirm and open the invoice
36 -
37   !workflow {model: account.invoice, ref: invoice_edi_1, action: invoice_open}
38 -
39   Then I export the customer invoice
40 -
41   !python {model: edi.edi}: |
42     import json
43     invoice_pool = self.pool.get('account.invoice')
44     invoice = invoice_pool.browse(cr, uid, ref("invoice_edi_1"))
45     edi_doc = self.generate_edi(cr, uid, [invoice])
46     assert isinstance(json.loads(edi_doc)[0], dict), 'EDI doc should be a JSON dict' 
47 -
48   Then I import a sample EDI document of another customer invoice from OpenERP 7.0
49 -
50   !python {model: account.invoice}: |
51     import time
52     edi_document = {
53         "__id": "account:b33adf8a-decd-11f0-a4de-702a04e25700.random_invoice_763jsms",
54         "__module": "account",
55         "__model": "account.invoice",
56         "__version": [7,0,0],
57         "internal_number": time.strftime("SAJ/%Y/070"),
58         "company_address": {
59                 "__id": "base:b33adf8a-decd-11f0-a4de-702a04e25700.main_address",
60                 "__module": "base",
61                 "__model": "res.partner", 
62                 "city": "Gerompont", 
63                 "name": "Company main address",
64                 "zip": "1367", 
65                 "country_id": ["base:b33adf8a-decd-11f0-a4de-702a04e25700.be", "Belgium"], 
66                 "phone": "(+32).81.81.37.00", 
67                 "street": "Chaussee de Namur 40",
68                 "bank_ids": [
69                     ["base:b33adf8a-decd-11f0-a4de-702a04e25700.res_partner_bank-ZrTWzesfsdDJzGbp","Sample bank: 70-123465789-156113"]
70                 ],
71         },
72         "company_id": ["account:b33adf8a-decd-11f0-a4de-702a04e25700.res_company_test11", "Thomson pvt. ltd."],
73         "currency": {
74             "__id": "base:b33adf8a-decd-11f0-a4de-702a04e25700.EUR",
75             "__module": "base",
76             "__model": "res.currency",
77             "code": "EUR",
78             "symbol": "€",
79         },
80         "partner_id": ["account:b33adf8a-decd-11f0-a4de-702a04e25700.res_partner_test20", "Junjun wala"],
81         "partner_address": {
82                 "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.res_partner_address_7wdsjasdjh",
83                 "__module": "base",
84                 "__model": "res.partner",
85                 "name": "Default Address",
86                 "phone": "(+32).81.81.37.00", 
87                 "street": "Chaussee de Namur 40", 
88                 "city": "Gerompont", 
89                 "zip": "1367", 
90                 "country_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.be", "Belgium"], 
91         },
92         "date_invoice": time.strftime('%Y-%m-%d'),
93         "name": "sample invoice",
94         "tax_line": [{
95                 "__id": "account:b33adf8a-decd-11f0-a4de-702a04e25700.account_invoice_tax-4g4EutbiEMVl",
96                 "__module": "account",
97                 "__model": "account.invoice.tax",
98                 "amount": 1000.0,
99                 "manual": True,
100                 "name": "sale tax",
101         }],
102         "type": "out_invoice",
103         "invoice_line": [{
104                 "__module": "account",
105                 "__model": "account.invoice.line",
106                 "__id": "account:b33adf8a-decd-11f0-a4de-702a04e25700.account_invoice_line-1RP3so",
107                 "uos_id": ["product:b33adf8a-decd-11f0-a4de-702a04e25700.product_uom_unit", "Unit"],
108                 "name": "PC Assemble SC234",
109                 "price_unit": 10.0,
110                 "product_id": ["product:b33adf8a-decd-11f0-a4de-702a04e25700.product_product_3", "[PCSC234] PC Assemble SC234"],
111                 "quantity": 1.0
112         },
113         {
114                 "__module": "account",
115                 "__model": "account.invoice.line",
116                 "__id": "account:b33adf8a-decd-11f0-a4de-702a04e25700.account_invoice_line-u2XV5",
117                 "uos_id": ["product:b33adf8a-decd-11f0-a4de-702a04e25700.product_uom_unit", "Unit"],
118                 "name": "PC on Demand",
119                 "price_unit": 100.0,
120                 "product_id": ["product:b33adf8a-decd-11f0-a4de-702a04e25700.product_product_5", "[PC-DEM] PC on Demand"],
121                 "quantity": 5.0
122         }]
123     }
124     invoice_id = self.edi_import(cr, uid, edi_document, context=context)
125     assert invoice_id, 'EDI import failed'
126     invoice_new = self.browse(cr, uid, invoice_id)
127
128     # check bank info on partner
129     assert invoice_new.partner_id.supplier, "Imported partner should be a supplier, as we just imported the document as a supplier invoice"
130     assert len(invoice_new.partner_id.bank_ids) == 1, "Expected 1 bank entry related to partner"
131     bank_info = invoice_new.partner_id.bank_ids[0]
132     assert bank_info.acc_number == "Sample bank: 70-123465789-156113", 'Expected "Sample bank: 70-123465789-156113", got %s' % bank_info.acc_number
133
134     assert invoice_new.partner_id.supplier, 'Imported Partner is not marked as supplier'
135     assert invoice_new.reference == time.strftime("SAJ/%Y/070"), "internal number is not stored in reference"
136     assert invoice_new.reference_type == 'none', "reference type is not set to 'none'"
137     assert invoice_new.internal_number == False, "internal number is not reset"
138     assert invoice_new.journal_id.id, "journal id is not selected"
139     assert invoice_new.type == 'in_invoice', "Invoice type was not set properly"
140     assert len(invoice_new.invoice_line) == 2, "invoice lines are not same"
141     for inv_line in invoice_new.invoice_line:
142         if inv_line.name == 'PC Assemble SC234':
143             assert inv_line.uos_id.name == "Unit" , "uom is not same"
144             assert inv_line.price_unit == 10 , "price unit is not same"
145             assert inv_line.quantity == 1 , "product qty is not same"
146             assert inv_line.price_subtotal == 10, "price sub total is not same"
147         elif inv_line.name == 'PC on Demand':
148             assert inv_line.uos_id.name == "Unit" , "uom is not same"
149             assert inv_line.price_unit == 100 , "price unit is not same"
150             assert inv_line.quantity == 5 , "product qty is not same"
151             assert inv_line.price_subtotal == 500, "price sub total is not same"
152         else:
153             raise AssertionError('unknown invoice line: %s' % inv_line)
154     for inv_tax in invoice_new.tax_line:
155         assert inv_tax.manual, "tax line not set to manual"
156         assert inv_tax.account_id, "missing tax line account"
157 -
158   Then I import a sample EDI document of another customer invoice from OpenERP 6.1 (to test backwards compatibility)
159 -
160   !python {model: account.invoice}: |
161     import time
162     edi_document = {
163         "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.random_invoice_763jsms", 
164         "__module": "account", 
165         "__model": "account.invoice", 
166         "__version": [6,1,0], 
167         "internal_number": time.strftime("SAJ/%Y/061"), 
168         "company_address": {
169                 "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.main_address",
170                 "__module": "base",
171                 "__model": "res.partner.address", 
172                 "city": "Gerompont", 
173                 "zip": "1367", 
174                 "country_id": ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.be", "Belgium"], 
175                 "phone": "(+32).81.81.37.00", 
176                 "street": "Chaussee de Namur 40",
177                 "bank_ids": [
178                     ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_bank-ZrTWzesfsdDJzGbp","Sample bank: 123465789-156113"]
179                 ],
180         }, 
181         "company_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_company_test11", "Thomson pvt. ltd."], 
182         "currency": {
183             "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.EUR",
184             "__module": "base",
185             "__model": "res.currency",
186             "code": "EUR",
187             "symbol": "€",
188         }, 
189         "partner_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_test20", "Junjun wala"],
190         "partner_address": {
191                 "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.res_partner_address_7wdsjasdjh",
192                 "__module": "base",
193                 "__model": "res.partner.address",
194                 "phone": "(+32).81.81.37.00", 
195                 "street": "Chaussee de Namur 40", 
196                 "city": "Gerompont", 
197                 "zip": "1367", 
198                 "country_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.be", "Belgium"], 
199         },
200         "date_invoice": time.strftime('%Y-%m-%d'), 
201         "name": "sample invoice", 
202         "tax_line": [{
203                 "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_tax-4g4EutbiEMVl", 
204                 "__module": "account",
205                 "__model": "account.invoice.tax", 
206                 "amount": 1000.0, 
207                 "manual": True, 
208                 "name": "sale tax", 
209         }], 
210         "type": "out_invoice", 
211         "invoice_line": [{
212                 "__module": "account",
213                 "__model": "account.invoice.line",
214                 "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_line-1RP3so",
215                 "uos_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_uom_unit", "PCE"], 
216                 "name": "Basic PC", 
217                 "price_unit": 10.0, 
218                 "product_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_product_pc1", "[PC1] Basic PC"], 
219                 "quantity": 1.0
220         },
221         {
222                 "__module": "account",
223                 "__model": "account.invoice.line",
224                 "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_line-u2XV5",
225                 "uos_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_uom_unit", "PCE"], 
226                 "name": "Medium PC", 
227                 "price_unit": 100.0, 
228                 "product_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_product_pc3", "[PC3] Medium PC"], 
229                 "quantity": 5.0
230         }]
231     }
232     invoice_id = self.edi_import(cr, uid, edi_document, context=context)
233     assert invoice_id, 'EDI import failed'
234     invoice_new = self.browse(cr, uid, invoice_id)
235
236     # check bank info on partner
237     assert invoice_new.partner_id.supplier, "Imported partner should be a supplier, as we just imported the document as a supplier invoice"
238     assert len(invoice_new.partner_id.bank_ids) == 1, "Expected 1 bank entry related to partner"
239     bank_info = invoice_new.partner_id.bank_ids[0]
240     assert bank_info.acc_number == "Sample bank: 123465789-156113", 'Expected "Sample bank: 123465789-156113", got %s' % bank_info.acc_number
241
242     assert invoice_new.partner_id.supplier, 'Imported Partner is not marked as supplier'
243     assert invoice_new.reference == time.strftime("SAJ/%Y/061"), "internal number is not stored in reference"
244     assert invoice_new.reference_type == 'none', "reference type is not set to 'none'"
245     assert invoice_new.internal_number == False, "internal number is not reset"
246     assert invoice_new.journal_id.id, "journal id is not selected"
247     assert invoice_new.type == 'in_invoice', "Invoice type was not set properly"
248     assert len(invoice_new.invoice_line) == 2, "invoice lines are not same"
249     for inv_line in invoice_new.invoice_line:
250         if inv_line.name == 'Basic PC':
251             assert inv_line.uos_id.name == "PCE" , "uom is not same"
252             assert inv_line.price_unit == 10 , "price unit is not same"
253             assert inv_line.quantity == 1 , "product qty is not same"
254             assert inv_line.price_subtotal == 10, "price sub total is not same"
255         elif inv_line.name == 'Medium PC':
256             assert inv_line.uos_id.name == "PCE" , "uom is not same"
257             assert inv_line.price_unit == 100 , "price unit is not same"
258             assert inv_line.quantity == 5 , "product qty is not same"
259             assert inv_line.price_subtotal == 500, "price sub total is not same"
260         else:
261             raise AssertionError('unknown invoice line: %s' % inv_line)
262     for inv_tax in invoice_new.tax_line:
263         assert inv_tax.manual, "tax line not set to manual"
264         assert inv_tax.account_id, "missing tax line account"