Initial commit: Pos packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:50 +02:00
commit 95dfb9edb0
1301 changed files with 264148 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# 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

View file

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class PosConfig(models.Model):
_inherit = 'pos.config'
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.')
@api.model
def _default_discount_value_on_module_install(self):
configs = self.env['pos.config'].search([])
open_configs = (
self.env['pos.session']
.search(['|', ('state', '!=', 'closed'), ('rescue', '=', True)])
.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)
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
def open_ui(self):
for config in self:
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()

View file

@ -0,0 +1,21 @@
# -*- 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,22 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
# pos.config fields
pos_discount_pc = fields.Float(related='pos_config_id.discount_pc', readonly=False)
pos_discount_product_id = fields.Many2one('product.product', compute='_compute_pos_discount_product_id', store=True, readonly=False)
@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']
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):
res_config.pos_discount_product_id = discount_product
else:
res_config.pos_discount_product_id = False