[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 <adgu@odoo.com>
This commit is contained in:
Loukas Wets (lowe)
2023-05-17 10:33:53 +02:00
parent a4ab4fa76c
commit 8a2e9c74ba
4 changed files with 35 additions and 13 deletions
+10 -6
View File
@@ -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:
+3 -7
View File
@@ -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,
@@ -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,
@@ -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)