From 8a2e9c74ba1ae99470149987556b2771ba0579a2 Mon Sep 17 00:00:00 2001 From: "Loukas Wets (lowe)" Date: Thu, 20 Apr 2023 11:49:01 +0000 Subject: [PATCH] [IMP] point_of_sale: set a pos config when a new company is created A new POS config with the name `Shop` is created when a new company is created with a dedicated fiscal postion and if `point_of_sale` is installed. A `Bank` payement method is created for the POS, as well as a `Customer Account` payement method. If a there is a cash journal that is not already linked to a payement method it would create a cash payement method for the dedicated POS. If the module `pos_restaurant`is installed it would also create a POS config with the name `Bar` of type restaurant with the same specification as for the normal pos config `Shop`. Since the changes create default configs along with payement methods, there was some conflicts with the test instances. Therefore the payement methods where unlink in the set up of the test to resolve the conflicts. task-3244511 closes odoo/odoo#119221 Related: odoo/enterprise#41003 Signed-off-by: adgu-odoo --- addons/point_of_sale/models/pos_config.py | 16 ++++++++++------ addons/point_of_sale/tests/common.py | 10 +++------- addons/point_of_sale/tests/test_frontend.py | 1 + addons/pos_restaurant/models/pos_config.py | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 856df9889f7..bc65d05fd9c 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -573,7 +573,14 @@ class PosConfig(models.Model): if not companies: companies = self.env['res.company'].search([]) for company in companies.filtered('chart_template'): - pos_configs = self.search([('company_id', '=', company.id)]) + pos_configs = self.search([('company_id', '=', company.id), ('module_pos_restaurant', '=', False)]) + if not pos_configs: + self = self.with_company(company) + pos_configs = self.env['pos.config'].create({ + 'name': 'Shop', + 'company_id': company.id, + 'module_pos_restaurant': False, + }) pos_configs.setup_defaults(company) def setup_defaults(self, company): @@ -594,13 +601,10 @@ class PosConfig(models.Model): cash_journal = self.env['account.journal'].search([('company_id', '=', company.id), ('type', '=', 'cash')], limit=1) bank_journal = self.env['account.journal'].search([('company_id', '=', company.id), ('type', '=', 'bank')], limit=1) payment_methods = self.env['pos.payment.method'] - if cash_journal: + if cash_journal and len(cash_journal.pos_payment_method_ids.ids) == 0: payment_methods |= payment_methods.create({ 'name': _('Cash'), - 'journal_id': self.env['account.journal'].create({ - 'name': "Cash", - 'type': 'cash', - }).id, + 'journal_id': cash_journal.id, 'company_id': company.id, }) if bank_journal: diff --git a/addons/point_of_sale/tests/common.py b/addons/point_of_sale/tests/common.py index bebfa22897b..17543c3de1f 100644 --- a/addons/point_of_sale/tests/common.py +++ b/addons/point_of_sale/tests/common.py @@ -57,6 +57,7 @@ class TestPointOfSaleCommon(ValuationReconciliationTestCommon): 'available_in_pos': True, 'list_price': 1.28, }) + cls.company_data['default_journal_cash'].pos_payment_method_ids.unlink() cls.cash_payment_method = cls.env['pos.payment.method'].create({ 'name': 'Cash', 'receivable_account_id': cls.company_data['default_account_receivable'].id, @@ -153,13 +154,7 @@ class TestPoSCommon(ValuationReconciliationTestCommon): # Set basic defaults cls.company = cls.company_data['company'] - cls.pos_sale_journal = cls.env['account.journal'].create({ - 'type': 'general', - 'name': 'Point of Sale Test', - 'code': 'POSS', - 'company_id': cls.company.id, - 'sequence': 20 - }) + cls.pos_sale_journal = cls.env['account.journal'].search([('company_id', '=', cls.company.id), ('code', '=', 'POSS')]) cls.sales_account = cls.company_data['default_account_revenue'] cls.invoice_journal = cls.company_data['default_journal_sale'] cls.receivable_account = cls.company_data['default_account_receivable'] @@ -247,6 +242,7 @@ class TestPoSCommon(ValuationReconciliationTestCommon): 'available_pricelist_ids': cls.currency_pricelist.ids, 'pricelist_id': cls.currency_pricelist.id, }) + cls.company_data['default_journal_cash'].pos_payment_method_ids.unlink() cls.cash_pm1 = cls.env['pos.payment.method'].create({ 'name': 'Cash', 'journal_id': cls.company_data['default_journal_cash'].id, diff --git a/addons/point_of_sale/tests/test_frontend.py b/addons/point_of_sale/tests/test_frontend.py index d3d112ebdab..690c82523e1 100644 --- a/addons/point_of_sale/tests/test_frontend.py +++ b/addons/point_of_sale/tests/test_frontend.py @@ -65,6 +65,7 @@ class TestPointOfSaleHttpCommon(AccountTestInvoicingHttpCommon): 'name': 'Bank', 'journal_id': cls.bank_journal.id, }) + env['pos.config'].search([]).unlink() cls.main_pos_config = env['pos.config'].create({ 'name': 'Shop', 'module_pos_restaurant': False, diff --git a/addons/pos_restaurant/models/pos_config.py b/addons/pos_restaurant/models/pos_config.py index 6aa8f7bf008..64e7e903ba2 100644 --- a/addons/pos_restaurant/models/pos_config.py +++ b/addons/pos_restaurant/models/pos_config.py @@ -63,3 +63,24 @@ class PosConfig(models.Model): 'company_id': company.id, }) pos_config.write({'payment_method_ids': [(6, 0, payment_methods.ids)]}) + + @api.model + def post_install_pos_localisation(self, companies=False): + self = self.sudo() + if not companies: + companies = self.env['res.company'].search([]) + for company in companies.filtered('chart_template'): + pos_configs = self.search([('company_id', '=', company.id), ('module_pos_restaurant', '=', True)]) + if not pos_configs: + self = self.with_company(company) + pos_configs = self.env['pos.config'].create({ + 'name': 'Bar', + 'company_id': company.id, + 'module_pos_restaurant': True, + 'iface_splitbill': True, + 'iface_printbill': True, + 'iface_orderline_notes': True, + + }) + pos_configs.setup_defaults(company) + super(PosConfig, self).post_install_pos_localisation(companies)