Skip to content
Permalink
Browse files

[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.

task: bug fix
  • Loading branch information...
rhe-odoo committed Sep 11, 2019
1 parent 6c7c97a commit d0d074225671cb32ce43d87c7621028de04bfb57
Showing with 11 additions and 19 deletions.
  1. +6 −6 addons/point_of_sale/data/point_of_sale_data.xml
  2. +5 −13 addons/pos_discount/models/pos_config.py
@@ -30,17 +30,17 @@
</record>

<record id="product_product_consumable" model="product.product">
<field name="name">Miscellaneous</field>
<field name="name">Discount</field>
<field name="available_in_pos">True</field>
<field name="standard_price">13.0</field>
<field name="list_price">18.0</field>
<field name="weight">0.01</field>
<field name="standard_price">0.00</field>
<field name="list_price">0.00</field>
<field name="weight">0.00</field>
<field name="type">consu</field>
<field name="categ_id" ref="point_of_sale.product_category_pos"/>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="default_code">MISC</field>
<field name="image_1920" type="base64" file="point_of_sale/static/img/product_product_49-image.jpg"/>
<field name="default_code">DISC</field>
<field name="purchase_ok">False</field>
</record>

<record id="uom.product_uom_categ_unit" model="uom.category">
@@ -7,19 +7,11 @@
class PosConfig(models.Model):
_inherit = 'pos.config'

def _default_discount_product_id(self):
return self.env.ref("point_of_sale.product_product_consumable")

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_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
domain="[('available_in_pos', '=', True), ('sale_ok', '=', True)]", help='The product used to model the discount.',
default=lambda self: self._default_discount_product_id())

0 comments on commit d0d0742

Please sign in to comment.
You can’t perform that action at this time.