19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:29:53 +01:00
parent 6e54c1af6c
commit 3ca647e428
1087 changed files with 132065 additions and 108499 deletions

View file

@ -2,5 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import pos_config
from . import pos_session
from . import res_config_settings
from . import product_template

View file

@ -11,7 +11,7 @@ class PosConfig(models.Model):
iface_discount = fields.Boolean(string='Order Discounts', help='Allow the cashier to give discounts on the whole order.')
discount_pc = fields.Float(string='Discount Percentage', help='The default discount percentage when clicking on the Discount button', default=10.0)
discount_product_id = fields.Many2one('product.product', string='Discount Product',
domain="[('sale_ok', '=', True)]", help='The product used to apply the discount on the ticket.')
domain=[('sale_ok', '=', True)], help='The product used to apply the discount on the ticket.')
@api.model
def _default_discount_value_on_module_install(self):
@ -22,7 +22,7 @@ class PosConfig(models.Model):
.mapped('config_id')
)
# Do not modify configs where an opened session exists.
product = self.env.ref("point_of_sale.product_product_consumable", raise_if_not_found=False)
product = self.env.ref("pos_discount.product_product_consumable", raise_if_not_found=False)
for conf in (configs - open_configs):
conf.discount_product_id = product if conf.module_pos_discount and product and (not product.company_id or product.company_id == conf.company_id) else False
@ -31,3 +31,8 @@ class PosConfig(models.Model):
if not self.current_session_id and config.module_pos_discount and not config.discount_product_id:
raise UserError(_('A discount product is needed to use the Global Discount feature. Go to Point of Sale > Configuration > Settings to set it.'))
return super().open_ui()
def _get_special_products(self):
res = super()._get_special_products()
default_discount_product = self.env.ref('pos_discount.product_product_consumable', raise_if_not_found=False) or self.env['product.product']
return res | self.env['pos.config'].search([]).mapped('discount_product_id') | default_discount_product

View file

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.osv.expression import OR
class PosSession(models.Model):
_inherit = 'pos.session'
def _get_pos_ui_product_product(self, params):
result = super()._get_pos_ui_product_product(params)
discount_product_id = self.config_id.discount_product_id.id
product_ids_set = {product['id'] for product in result}
if self.config_id.module_pos_discount and discount_product_id not in product_ids_set:
productModel = self.env['product.product'].with_context(**params['context'])
product = productModel.search_read([('id', '=', discount_product_id)], fields=params['search_params']['fields'])
self._process_pos_ui_product_product(product)
result.extend(product)
return result

View file

@ -0,0 +1,19 @@
from odoo import models, api
class ProductTemplate(models.Model):
_inherit = 'product.template'
@api.model
def _load_pos_data_read(self, records, config):
read_data = super()._load_pos_data_read(records, config)
discount_product_id = config.discount_product_id.id
product_ids_set = {product['id'] for product in read_data}
if config.module_pos_discount and discount_product_id not in product_ids_set:
productModel = self.env['product.template'].with_context({**self.env.context, 'display_default_code': False})
fields = self.env['product.template']._load_pos_data_fields(config)
product = productModel.search_read([('id', '=', discount_product_id)], fields=fields, load=False)
read_data.extend(product)
return read_data

View file

@ -13,7 +13,7 @@ class ResConfigSettings(models.TransientModel):
@api.depends('company_id', 'pos_module_pos_discount', 'pos_config_id')
def _compute_pos_discount_product_id(self):
default_product = self.env.ref("point_of_sale.product_product_consumable", raise_if_not_found=False) or self.env['product.product']
default_product = self.env.ref("pos_discount.product_product_consumable", raise_if_not_found=False) or self.env['product.product']
for res_config in self:
discount_product = res_config.pos_config_id.discount_product_id or default_product
if res_config.pos_module_pos_discount and (not discount_product.company_id or discount_product.company_id == res_config.company_id):