[IMP] pos_restaurant, *: share payment methods
*: point_of_sale - Makes the default shop and restaurant use the same default payment methods except cash payment methods that are individual. - Adds a default cash payment method to the default restaurant. closes odoo/odoo#126953 Task-id: 3378032 Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -5,7 +5,7 @@ from datetime import datetime
|
||||
from uuid import uuid4
|
||||
import pytz
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import api, fields, models, _, Command
|
||||
from odoo.osv.expression import OR
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
@@ -669,6 +669,34 @@ class PosConfig(models.Model):
|
||||
domain = OR([domain, [('id', '=', self.tip_product_id.id)]])
|
||||
return domain
|
||||
|
||||
def _link_same_non_cash_payment_methods_if_exists(self, source_config_ref_id):
|
||||
src_cfg = self.env.ref(source_config_ref_id, raise_if_not_found=False)
|
||||
if src_cfg and src_cfg.company_id == self.company_id:
|
||||
self._link_same_non_cash_payment_methods(src_cfg)
|
||||
|
||||
def _link_same_non_cash_payment_methods(self, source_config):
|
||||
pms = source_config.payment_method_ids.filtered(lambda pm: not pm.is_cash_count)
|
||||
if pms:
|
||||
self.payment_method_ids = [Command.link(pm.id) for pm in pms]
|
||||
|
||||
def _ensure_cash_payment_method(self, journal_code, name):
|
||||
self.ensure_one()
|
||||
if not self.company_id.chart_template or self.payment_method_ids.filtered('is_cash_count'):
|
||||
return
|
||||
company_id = self.company_id.id
|
||||
cash_journal = self.env['account.journal'].create({
|
||||
'name': name,
|
||||
'code': journal_code,
|
||||
'type': 'cash',
|
||||
'company_id': company_id,
|
||||
})
|
||||
cash_pm = self.env['pos.payment.method'].create({
|
||||
'name': name,
|
||||
'journal_id': cash_journal.id,
|
||||
'company_id': company_id,
|
||||
})
|
||||
self.payment_method_ids = [Command.link(cash_pm.id)]
|
||||
|
||||
def get_limited_products_loading(self, fields):
|
||||
tables, where_clause, params = self.env['product.product']._where_calc(
|
||||
self._get_available_product_domain()
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<field name="limit_categories">False</field>
|
||||
</record>
|
||||
|
||||
<function model="pos.config" name="_set_tips_after_payment_if_country_custom">
|
||||
<function model="pos.config" name="_setup_main_restaurant_defaults">
|
||||
<value eval="[ref('pos_config_main_restaurant')]"/>
|
||||
</function>
|
||||
</data>
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
<field name="name">Drinks</field>
|
||||
<field name="image_128" type="base64" file="pos_restaurant/static/img/drink_category.png" />
|
||||
</record>
|
||||
|
||||
|
||||
<record id="product_category_pos_food" model="product.category">
|
||||
<field name="parent_id" ref="point_of_sale.product_category_pos"/>
|
||||
<field name="name">Food</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="food" model="pos.category">
|
||||
<field name="name">Food</field>
|
||||
<field name="image_128" type="base64" file="pos_restaurant/static/img/food_category.png" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import api, fields, models, _
|
||||
import json
|
||||
from collections import defaultdict
|
||||
|
||||
@@ -93,6 +93,7 @@ class PosConfig(models.Model):
|
||||
self = self.sudo()
|
||||
if not companies:
|
||||
companies = self.env['res.company'].search([])
|
||||
super(PosConfig, self).post_install_pos_localisation(companies)
|
||||
for company in companies.filtered('chart_template'):
|
||||
pos_configs = self.search([
|
||||
*self.env['account.journal']._check_company_domain(company),
|
||||
@@ -109,4 +110,21 @@ class PosConfig(models.Model):
|
||||
|
||||
})
|
||||
pos_configs.setup_defaults(company)
|
||||
super(PosConfig, self).post_install_pos_localisation(companies)
|
||||
|
||||
def setup_defaults(self, company):
|
||||
main_restaurant = self.env.ref('pos_restaurant.pos_config_main_restaurant', raise_if_not_found=False)
|
||||
main_restaurant_is_present = main_restaurant and self.filtered(lambda cfg: cfg.id == main_restaurant.id)
|
||||
if main_restaurant_is_present:
|
||||
non_main_restaurant_configs = self - main_restaurant
|
||||
non_main_restaurant_configs.assign_payment_journals(company)
|
||||
main_restaurant._setup_main_restaurant_defaults()
|
||||
self.generate_pos_journal(company)
|
||||
self.setup_invoice_journal(company)
|
||||
else:
|
||||
super().setup_defaults(company)
|
||||
|
||||
def _setup_main_restaurant_defaults(self):
|
||||
self.ensure_one()
|
||||
self._set_tips_after_payment_if_country_custom()
|
||||
self._link_same_non_cash_payment_methods_if_exists('point_of_sale.pos_config_main')
|
||||
self._ensure_cash_payment_method('MRCSH', _('Cash Restaurant'))
|
||||
|
||||
Reference in New Issue
Block a user