diff options
| author | Robin Heinz <rhe@odoo.com> | 2019-09-11 06:25:50 +0000 |
|---|---|---|
| committer | Robin Heinz <rhe@odoo.com> | 2019-09-13 13:45:51 +0000 |
| commit | 1a3dcfeae658bf3d6411662cbb2c8c340c34f07f (patch) | |
| tree | f33b86835e9ae7514ed15d010688857c875a3d6e /addons/pos_discount | |
| parent | 58a83d12228fbbd4e9dde542e133d264204ee0f3 (diff) | |
[FIX] point_of_sale: default global discount
Change the default value of the miscellaneous product to a discount product. When the module pos_discount is installed, the default value will now be the discount product.
closes odoo/odoo#36665
Task: bug fix
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_discount')
| -rw-r--r-- | addons/pos_discount/models/pos_config.py | 23 | ||||
| -rw-r--r-- | addons/pos_discount/views/pos_discount_views.xml | 4 |
2 files changed, 15 insertions, 12 deletions
diff --git a/addons/pos_discount/models/pos_config.py b/addons/pos_discount/models/pos_config.py index 46272218f67..0bc2d846a43 100644 --- a/addons/pos_discount/models/pos_config.py +++ b/addons/pos_discount/models/pos_config.py @@ -8,18 +8,17 @@ 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') + 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="[('available_in_pos', '=', True), ('sale_ok', '=', True)]", help='The product used to model the discount.') - @api.onchange('module_pos_discount') - def _onchange_module_pos_discount(self): - if self.module_pos_discount: - self.discount_product_id = self.env.ref('point_of_sale.product_product_consumable', raise_if_not_found=False) - if not self.discount_product_id or not self.discount_product_id.available_in_pos or not self.discount_product_id.sale_ok: - domain = [('available_in_pos', '=', True), ('sale_ok', '=', True)] - self.discount_product_id = self.env['product.product'].search(domain, limit=1) - self.discount_pc = 10.0 - else: - self.discount_product_id = False - self.discount_pc = 0.0 + @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([]) + for conf in configs: + conf._default_discount_product_id() diff --git a/addons/pos_discount/views/pos_discount_views.xml b/addons/pos_discount/views/pos_discount_views.xml index 7f7cc0c2dd9..0e38b16af64 100644 --- a/addons/pos_discount/views/pos_discount_views.xml +++ b/addons/pos_discount/views/pos_discount_views.xml @@ -17,4 +17,8 @@ </div> </field> </record> + + <data noupdate="1"> + <function model="pos.config" name="_default_discount_value_on_module_install"/> + </data> </odoo> |
