Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 #45038 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |