diff options
| author | Joren Van Onder <jov@odoo.com> | 2020-02-07 23:54:51 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2020-02-12 13:50:27 +0000 |
| commit | 67e49915b51ace0dd9b7e17bc0b6247c7cb77ffb (patch) | |
| tree | 47c3ae9c0d86ea3c69daaf777fc0da8b4d391925 /addons | |
| parent | 0cc95583bfcc96c428a527742a86e0d1bc497bf9 (diff) | |
[FIX] point_of_sale: pick default pricelist in the right company
To reproduce:
- Create a second company with the same currency as the first,
- Assign the first pricelist with that currency (based on _order) to
the second company
- Install the POS, or create a new pos.config while in the first
company
The above results in:
raise ValidationError("The selected pricelists must belong to no
company or the company of the point of sale")
opw-2192658
closes odoo/odoo#45199
X-original-commit: f6e73f69350b3d0fef5f24e0073f68e52da3a36d
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/point_of_sale/models/pos_config.py | 2 | ||||
| -rw-r--r-- | addons/point_of_sale/tests/__init__.py | 1 | ||||
| -rw-r--r-- | addons/point_of_sale/tests/test_point_of_sale.py | 63 |
3 files changed, 65 insertions, 1 deletions
diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index b8026a439f2..3f77a528969 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -88,7 +88,7 @@ class PosConfig(models.Model): return self.env['pos.payment.method'].search([('split_transactions', '=', False), ('company_id', '=', self.env.company.id)]) def _default_pricelist(self): - return self.env['product.pricelist'].search([('currency_id', '=', self.env.company.currency_id.id)], limit=1) + return self.env['product.pricelist'].search([('company_id', 'in', (False, self.env.company.id)), ('currency_id', '=', self.env.company.currency_id.id)], limit=1) def _get_group_pos_manager(self): return self.env.ref('point_of_sale.group_pos_manager') diff --git a/addons/point_of_sale/tests/__init__.py b/addons/point_of_sale/tests/__init__.py index d003102e887..43cf85459af 100644 --- a/addons/point_of_sale/tests/__init__.py +++ b/addons/point_of_sale/tests/__init__.py @@ -5,6 +5,7 @@ from . import test_point_of_sale_flow from . import test_frontend from . import test_point_of_sale_ui from . import test_anglo_saxon +from . import test_point_of_sale from . import test_pos_setup from . import test_pos_basic_config from . import test_pos_products_with_tax diff --git a/addons/point_of_sale/tests/test_point_of_sale.py b/addons/point_of_sale/tests/test_point_of_sale.py new file mode 100644 index 00000000000..83cf6c0ca16 --- /dev/null +++ b/addons/point_of_sale/tests/test_point_of_sale.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests.common import TransactionCase + + +class TestPointOfSale(TransactionCase): + def setUp(self): + super(TestPointOfSale, self).setUp() + + # ignore pre-existing pricelists for the purpose of this test + self.env["product.pricelist"].search([]).write({"active": False}) + + self.currency = self.env.ref("base.USD") + self.company1 = self.env["res.company"].create({ + "name": "company 1", + "currency_id": self.currency.id + }) + self.company2 = self.env["res.company"].create({ + "name": "company 2", + "currency_id": self.currency.id + }) + self.company2_pricelist = self.env["product.pricelist"].create({ + "name": "company 2 pricelist", + "currency_id": self.currency.id, + "company_id": self.company2.id, + "sequence": 1, # force this pricelist to be first + }) + + self.env.user.company_id = self.company1 + + def test_default_pricelist_with_company(self): + """ Verify that the default pricelist belongs to the same company as the config """ + company1_pricelist = self.env["product.pricelist"].create({ + "name": "company 1 pricelist", + "currency_id": self.currency.id, + "company_id": self.company1.id, + "sequence": 2, + }) + + # make sure this doesn't pick the company2 pricelist + new_config = self.env["pos.config"].create({ + "name": "usd config" + }) + + self.assertEqual(new_config.pricelist_id, company1_pricelist, + "POS config incorrectly has pricelist %s" % new_config.pricelist_id.display_name) + + def test_default_pricelist_without_company(self): + """ Verify that a default pricelist without a company works """ + universal_pricelist = self.env["product.pricelist"].create({ + "name": "universal pricelist", + "currency_id": self.currency.id, + "sequence": 2, + }) + + # make sure this doesn't pick the company2 pricelist + new_config = self.env["pos.config"].create({ + "name": "usd config" + }) + + self.assertEqual(new_config.pricelist_id, universal_pricelist, + "POS config incorrectly has pricelist %s" % new_config.pricelist_id.display_name) |
