Debian Codegraph @

addons/point_of_sale/tests/test_pos_setup.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import tools
5 import odoo
6 from odoo.addons.point_of_sale.tests.common import TestPoSCommon
7 from odoo.exceptions import ValidationError
8
9 @odoo.tests.tagged('post_install', '-at_install')
10 class TestPoSSetup(TestPoSCommon):
11 """ This group of tests is for sanity check in setting up global records which will be used
12 in each testing.
13
14 If a test fails here, then it means there are inconsistencies in what we expect in the setup.
15 """
16 def setUp(self):
17 super(TestPoSSetup, self).setUp()
18
19 self.config = self.basic_config
20 self.products = [
21 self.create_product('Product 1', self.categ_basic, lst_price=10.0, standard_price=5),
22 self.create_product('Product 2', self.categ_basic, lst_price=20.0, standard_price=10),
23 self.create_product('Product 3', self.categ_basic, lst_price=30.0, standard_price=15),
24 ]
25
26 def test_basic_config_values(self):
27
28 config = self.basic_config
29 self.assertEqual(config.currency_id, self.company_currency)
30 self.assertEqual(config.pricelist_id.currency_id, self.company_currency)
31
32 def test_other_currency_config_values(self):
33 config = self.other_currency_config
34 self.assertEqual(config.currency_id, self.other_currency)
35 self.assertEqual(config.pricelist_id.currency_id, self.other_currency)
36
37 def test_product_categories(self):
38 # check basic product category
39 # it is expected to have standard and manual_periodic valuation
40 self.assertEqual(self.categ_basic.property_cost_method, 'standard')
41 self.assertEqual(self.categ_basic.property_valuation, 'periodic')
42 # check anglo saxon product category
43 # this product categ is expected to have fifo and real_time valuation
44 self.assertEqual(self.categ_anglo.property_cost_method, 'fifo')
45 self.assertEqual(self.categ_anglo.property_valuation, 'real_time')
46
47 def test_product_price(self):
48 def get_price(pricelist, product):
49 return pricelist._get_product_price(product, 1)
50
51
52 # check usd pricelist
53 pricelist = self.basic_config.pricelist_id
54 for product in self.products:
55 self.assertAlmostEqual(get_price(pricelist, product), product.lst_price)
56
57 # check eur pricelist
58 # exchange rate to the other currency is set to 0.5, thus, lst_price
59 # is expected to have half its original value.
60 pricelist = self.other_currency_config.pricelist_id
61 for product in self.products:
62 self.assertAlmostEqual(get_price(pricelist, product), product.lst_price * 0.5)
63
64 def test_taxes(self):
65 tax7 = self.taxes['tax7']
66 self.assertEqual(tax7.name, 'Tax 7%')
67 self.assertAlmostEqual(tax7.amount, 7)
68 self.assertEqual(tax7.invoice_repartition_line_ids.mapped('account_id').id, self.tax_received_account.id)
69 tax10 = self.taxes['tax10']
70 self.assertEqual(tax10.name, 'Tax 10%')
71 self.assertAlmostEqual(tax10.amount, 10)
72 self.assertEqual(tax10.price_include, True)
73 self.assertEqual(tax10.invoice_repartition_line_ids.mapped('account_id').id, self.tax_received_account.id)
74 tax_group_7_10 = self.taxes['tax_group_7_10']
75 self.assertEqual(tax_group_7_10.name, 'Tax 7+10%')
76 self.assertEqual(tax_group_7_10.amount_type, 'group')
77 self.assertEqual(sorted(tax_group_7_10.children_tax_ids.ids), sorted((tax7 | tax10).ids))
78
79 def test_archive_used_journal(self):
80 journal = self.env['account.journal'].create({
81 'name': 'BANKOS',
82 'company_id': self.company.id,
83 'code': 'BANKOS',
84 'type': 'bank',
85 'invoice_reference_type': 'invoice',
86 'invoice_reference_model': 'odoo'
87 })
88 payment_method = self.env['pos.payment.method'].create({'name': 'Lets Pay for Tests', 'journal_id': journal.id})
89 self.basic_config.write({'payment_method_ids': [payment_method.id]})
90 journal.write({'pos_payment_method_ids': [payment_method.id]})
91 session = self.env['pos.session'].create(
92 {
93 'name': 'lets sell some tests',
94 'config_id': self.basic_config.id,
95 'user_id': self.env.user.id,
96 'state': 'opened'
97 }
98 )
99 order = self.env['pos.order'].create(
100 {
101 'name': 'MIX',
102 'amount_tax': 0,
103 'amount_total': 0,
104 'amount_paid': 0,
105 'amount_return': 0,
106 'company_id': self.company.id,
107 'pricelist_id': self.currency_pricelist.id,
108 'session_id': session.id
109 }
110 )
111 self.env['pos.payment'].create(
112 {
113 'amount': 100,
114 'payment_date': '2025-01-01',
115 'payment_method_id': payment_method.id,
116 'pos_order_id': order.id
117 }
118 )
119 with self.assertRaises(ValidationError):
120 journal.action_archive()