forked from OCA/account-invoicing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_account_invoice_line_description.py
99 lines (92 loc) · 3.77 KB
/
test_account_invoice_line_description.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright 2017 - Tecnativa, S.L. - Luis M. Ontalba
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo.tests import Form
from odoo.tests.common import SavepointCase, tagged
@tagged("post_install", "-at_install")
class TestAccountInvoiceLineDescription(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.new_permission = cls.env.ref(
"account_invoice_line_description"
".group_use_product_description_per_inv_line"
)
cls.env.user.groups_id |= cls.new_permission
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.journal_sale = cls.env["account.journal"].create(
{"name": "Test Sale Journal", "code": "TSJ", "type": "sale"}
)
cls.product_category = cls.env["product.category"].create(
{"name": "Test Product category"}
)
cls.product_sale = cls.env["product.product"].create(
{
"name": "Test Sale Product",
"sale_ok": True,
"type": "consu",
"categ_id": cls.product_category.id,
"description_sale": "Test Description Sale",
"lst_price": 0,
}
)
cls.account_type_regular = cls.env["account.account.type"].create(
{"name": "regular", "type": "other", "internal_group": "income"}
)
cls.account = cls.env["account.account"].create(
{
"name": "Test Account",
"code": "TA",
"user_type_id": cls.account_type_regular.id,
}
)
cls.journal_purchase = cls.env["account.journal"].create(
{"name": "Test Purchase Journal", "code": "TPJ", "type": "purchase"}
)
cls.product_purchase = cls.env["product.product"].create(
{
"name": "Test Purchase Product",
"purchase_ok": True,
"type": "consu",
"categ_id": cls.product_category.id,
"description_purchase": "Test Description Purchase",
"lst_price": 0,
}
)
invoice_sale = Form(
cls.env["account.move"].with_context(
default_move_type="out_invoice",
)
)
invoice_sale.partner_id = cls.partner
invoice_sale.journal_id = cls.journal_sale
with invoice_sale.invoice_line_ids.new() as line_form:
line_form.name = "Test Invoice Line"
line_form.price_unit = 500.0
line_form.quantity = 1
line_form.product_id = cls.product_sale
line_form.account_id = cls.account
cls.invoice_sale = invoice_sale.save()
invoice_purchase = Form(
cls.env["account.move"].with_context(
default_move_type="in_invoice",
)
)
invoice_purchase.partner_id = cls.partner
invoice_purchase.journal_id = cls.journal_purchase
with invoice_purchase.invoice_line_ids.new() as line_form:
line_form.name = "Test Invoice Line"
line_form.price_unit = 500.0
line_form.quantity = 1
line_form.product_id = cls.product_purchase
cls.invoice_purchase = invoice_purchase.save()
def test_onchange_product_id_sale(self):
self.invoice_sale.invoice_line_ids._onchange_product_id()
self.assertEqual(
self.product_sale.description_sale, self.invoice_sale.invoice_line_ids.name
)
def test_onchange_product_id_purchase(self):
self.invoice_purchase.invoice_line_ids._onchange_product_id()
self.assertEqual(
self.product_purchase.description_purchase,
self.invoice_purchase.invoice_line_ids.name,
)