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