[Fix] account :remove res.partner.addree and put use res.partner
[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_agrolait
9     currency_id: base.EUR
10     address_invoice_id: base.res_partner_address_8invoice
11     company_id: 1
12     account_id: account.a_pay
13     date_invoice: !eval "'%s' % (time.strftime('%Y-%m-%d'))"
14     name: selling product
15     type: 'out_invoice'
16     invoice_line:
17       - product_id: product.product_product_pc1
18         uos_id: 1
19         quantity: 1.0
20         price_unit: 10.0
21         name: 'basic pc'
22         account_id: account.a_pay
23     invoice_line:
24       - product_id: product.product_product_pc3
25         uos_id: 1
26         quantity: 5.0
27         price_unit: 100.0
28         name: 'Medium PC'
29         account_id: account.a_pay
30     tax_line:
31       - name: sale tax
32         account_id: account.a_pay
33         manual: True
34         amount: 1000.00
35 -
36   I confirm and open the invoice
37 -
38   !workflow {model: account.invoice, ref: invoice_edi_1, action: invoice_open}
39 -
40   Then I export the customer invoice
41 -
42   !python {model: edi.document}: |
43     invoice_pool = self.pool.get('account.invoice')
44     invoice = invoice_pool.browse(cr, uid, ref("invoice_edi_1"))
45     token = self.export_edi(cr, uid, [invoice])
46     assert token, 'Invalid EDI Token'
47 -
48   Then I import a sample EDI document of another customer invoice
49 -
50   !python {model: account.invoice}: |
51     import time
52     edi_document = {
53         "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.random_invoice_763jsms", 
54         "__module": "account", 
55         "__model": "account.invoice", 
56         "__version": [6,1,0], 
57         "internal_number": time.strftime("SAJ/%Y/002"), 
58         "company_address": {
59                 "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.main_address",
60                 "__module": "base",
61                 "__model": "res.partner", 
62                 "city": "Gerompont", 
63                 "zip": "1367", 
64                 "country_id": ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.be", "Belgium"], 
65                 "phone": "(+32).81.81.37.00", 
66                 "street": "Chaussee de Namur 40",
67                 "bank_ids": [
68                     ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_bank-ZrTWzesfsdDJzGbp","Sample bank: 123465789-156113"]
69                 ],
70         }, 
71         "company_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_company_test11", "Thomson pvt. ltd."], 
72         "currency": {
73             "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.EUR",
74             "__module": "base",
75             "__model": "res.currency",
76             "code": "EUR",
77             "symbol": "€",
78         }, 
79         "partner_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_test20", "Junjun wala"],
80         "partner_address": {
81                 "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.res_partner_address_7wdsjasdjh",
82                 "__module": "base",
83                 "__model": "res.partner",
84                 "phone": "(+32).81.81.37.00", 
85                 "street": "Chaussee de Namur 40", 
86                 "city": "Gerompont", 
87                 "zip": "1367", 
88                 "country_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.be", "Belgium"], 
89         },
90         "date_invoice": time.strftime('%Y-%m-%d'), 
91         "name": "sample invoice", 
92         "tax_line": [{
93                 "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_tax-4g4EutbiEMVl", 
94                 "__module": "account",
95                 "__model": "account.invoice.tax", 
96                 "amount": 1000.0, 
97                 "manual": True, 
98                 "name": "sale tax", 
99         }], 
100         "type": "out_invoice", 
101         "invoice_line": [{
102                 "__module": "account",
103                 "__model": "account.invoice.line",
104                 "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_line-1RP3so",
105                 "uos_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_uom_unit", "PCE"], 
106                 "name": "Basic PC", 
107                 "price_unit": 10.0, 
108                 "product_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_product_pc1", "[PC1] Basic PC"], 
109                 "quantity": 1.0
110         },
111         {
112                 "__module": "account",
113                 "__model": "account.invoice.line",
114                 "__id": "account:b22acf7a-ddcd-11e0-a4db-701a04e25543.account_invoice_line-u2XV5",
115                 "uos_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_uom_unit", "PCE"], 
116                 "name": "Medium PC", 
117                 "price_unit": 100.0, 
118                 "product_id": ["product:b22acf7a-ddcd-11e0-a4db-701a04e25543.product_product_pc3", "[PC3] Medium PC"], 
119                 "quantity": 5.0
120         }]
121     }
122     invoice_id = self.edi_import(cr, uid, edi_document, context=context)
123     assert invoice_id, 'EDI import failed'
124     invoice_new = self.browse(cr, uid, invoice_id)
125
126     # check bank info on partner
127     assert len(invoice_new.partner_id.bank_ids) == 1, "Expected 1 bank entry related to partner"
128     bank_info = invoice_new.partner_id.bank_ids[0]
129     assert bank_info.acc_number == "Sample bank: 123465789-156113", 'Expected "Sample bank: 123465789-156113", got %s' % bank_info.acc_number
130
131     assert invoice_new.partner_id.supplier, 'Imported Partner is not marked as supplier'
132     assert invoice_new.reference == time.strftime("SAJ/%Y/002"), "internal number is not stored in reference"
133     assert invoice_new.reference_type == 'none', "reference type is not set to 'none'"
134     assert invoice_new.internal_number == False, "internal number is not reset"
135     assert invoice_new.journal_id.id, "journal id is not selected"
136     assert invoice_new.type == 'in_invoice', "Invoice type was not set properly"
137     assert len(invoice_new.invoice_line) == 2, "invoice lines are not same"
138     for inv_line in invoice_new.invoice_line:
139         if inv_line.name == 'Basic PC':
140             assert inv_line.uos_id.name == "PCE" , "uom is not same"
141             assert inv_line.price_unit == 10 , "price unit is not same"
142             assert inv_line.quantity == 1 , "product qty is not same"
143             assert inv_line.price_subtotal == 10, "price sub total is not same"
144         elif inv_line.name == 'Medium PC':
145             assert inv_line.uos_id.name == "PCE" , "uom is not same"
146             assert inv_line.price_unit == 100 , "price unit is not same"
147             assert inv_line.quantity == 5 , "product qty is not same"
148             assert inv_line.price_subtotal == 500, "price sub total is not same"
149         else:
150             raise AssertionError('unknown invoice line: %s' % inv_line)
151     for inv_tax in invoice_new.tax_line:
152         assert inv_tax.manual, "tax line not set to manual"
153         assert inv_tax.account_id, "missing tax line account"