From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/pos_discount/models/__init__.py | 4 ++++ addons/pos_discount/models/pos_config.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 addons/pos_discount/models/__init__.py create mode 100644 addons/pos_discount/models/pos_config.py (limited to 'addons/pos_discount/models') diff --git a/addons/pos_discount/models/__init__.py b/addons/pos_discount/models/__init__.py new file mode 100644 index 00000000..eaa81f34 --- /dev/null +++ b/addons/pos_discount/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import pos_config diff --git a/addons/pos_discount/models/pos_config.py b/addons/pos_discount/models/pos_config.py new file mode 100644 index 00000000..a8f7f5f7 --- /dev/null +++ b/addons/pos_discount/models/pos_config.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +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', default=10.0) + discount_product_id = fields.Many2one('product.product', string='Discount Product', + domain="[('sale_ok', '=', True)]", help='The product used to model the discount.') + + @api.onchange('company_id','module_pos_discount') + def _default_discount_product_id(self): + product = self.env.ref("point_of_sale.product_product_consumable", raise_if_not_found=False) + self.discount_product_id = product if self.module_pos_discount and product and (not product.company_id or product.company_id == self.company_id) else False + + @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. + for conf in (configs - open_configs): + conf._default_discount_product_id() -- cgit v1.2.3