| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
import odoo |
| 5 |
|
| 6 |
from odoo import Command |
| 7 |
from odoo.addons.point_of_sale.tests.common import TestPoSCommon |
| 8 |
|
| 9 |
|
| 10 |
@odoo.tests.tagged('post_install', '-at_install') |
| 11 |
class TestConfigureShops(TestPoSCommon): |
| 12 |
""" Shops are now configured from the general settings. |
| 13 |
This test suite ensures that changes made in the general settings |
| 14 |
should reflect to the pos.config record pointed by the |
| 15 |
pos_config_id field. |
| 16 |
""" |
| 17 |
|
| 18 |
@classmethod |
| 19 |
def setUpClass(cls): |
| 20 |
super().setUpClass() |
| 21 |
# If not enabled (like in demo data), landing on res.config will try |
| 22 |
# to disable module_sale_quotation_builder and raise an issue |
| 23 |
group_order_template = cls.env.ref('sale_management.group_sale_order_template', raise_if_not_found=False) |
| 24 |
if group_order_template: |
| 25 |
cls.env.ref('base.group_user').write({"implied_ids": [(4, group_order_template.id)]}) |
| 26 |
|
| 27 |
def _remove_on_payment_taxes(self): |
| 28 |
""" Call this when testing the res.config.settings with Form. |
| 29 |
The `on_payment` taxes need to be removed, otherwise, a warning will show in the log. |
| 30 |
""" |
| 31 |
self.env['account.tax'].search([ |
| 32 |
('company_id', '=', self.env.company.id), ('tax_exigibility', '=', 'on_payment') |
| 33 |
]).unlink() |
| 34 |
|
| 35 |
def test_properly_set_pos_config_x2many_fields(self): |
| 36 |
"""Simulate what is done from the res.config.settings view when editing x2 many fields.""" |
| 37 |
|
| 38 |
self._remove_on_payment_taxes() |
| 39 |
pos_config = self.env['pos.config'].create({ |
| 40 |
'name': 'Shop 1', |
| 41 |
'module_pos_restaurant': False, |
| 42 |
'payment_method_ids': [ |
| 43 |
Command.create({ |
| 44 |
'name': 'Bank 1', |
| 45 |
'receivable_account_id': self.env.company.account_default_pos_receivable_account_id.id, |
| 46 |
'is_cash_count': False, |
| 47 |
'split_transactions': False, |
| 48 |
'company_id': self.env.company.id, |
| 49 |
}), |
| 50 |
Command.create({ |
| 51 |
'name': 'Bank 2', |
| 52 |
'receivable_account_id': self.env.company.account_default_pos_receivable_account_id.id, |
| 53 |
'is_cash_count': False, |
| 54 |
'split_transactions': False, |
| 55 |
'company_id': self.env.company.id, |
| 56 |
}), |
| 57 |
Command.create({ |
| 58 |
'name': 'Cash', |
| 59 |
'receivable_account_id': self.env.company.account_default_pos_receivable_account_id.id, |
| 60 |
'is_cash_count': True, |
| 61 |
'company_id': self.env.company.id, |
| 62 |
}) |
| 63 |
] |
| 64 |
}) |
| 65 |
|
| 66 |
# Manually simulate the unlinking of the second record and then save the settings. |
| 67 |
# It will be a set of link commands except the one we want to delete. |
| 68 |
linked_ids = pos_config.payment_method_ids.ids |
| 69 |
second_id = linked_ids[1] |
| 70 |
commands = [Command.link(_id) for _id in linked_ids if _id != second_id] |
| 71 |
|
| 72 |
pos_config.with_context(from_settings_view=True).write({ |
| 73 |
'payment_method_ids': commands |
| 74 |
}) |
| 75 |
|
| 76 |
self.assertTrue(second_id not in pos_config.payment_method_ids.ids) |
| 77 |
self.assertTrue(len(pos_config.payment_method_ids) == 2) |
| 78 |
|
| 79 |
def test_write_default_and_available_presets_on_multiple_pos_configs(self): |
| 80 |
preset = self.env['pos.preset'].create({'name': 'Preset 1'}) |
| 81 |
|
| 82 |
pos_config1 = self.env['pos.config'].create({'name': 'Shop 1', 'module_pos_restaurant': False}) |
| 83 |
pos_config2 = self.env['pos.config'].create({'name': 'Shop 2', 'module_pos_restaurant': False}) |
| 84 |
pos_config3 = self.env['pos.config'].create({'name': 'Shop 3', 'module_pos_restaurant': False}) |
| 85 |
|
| 86 |
pos_configs = pos_config1 | pos_config2 | pos_config3 |
| 87 |
|
| 88 |
pos_configs.write({ |
| 89 |
'use_presets': True, |
| 90 |
'available_preset_ids': [(6, 0, [preset.id])], |
| 91 |
'default_preset_id': preset.id, |
| 92 |
}) |