Skip to content

Commit

Permalink
[FIX] point_of_sale: default global discount
Browse files Browse the repository at this point in the history
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 13, 2019
1 parent a96048a commit 0c067f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
12 changes: 6 additions & 6 deletions addons/point_of_sale/data/point_of_sale_data.xml
Expand Up @@ -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">
Expand Down
Binary file not shown.
14 changes: 7 additions & 7 deletions addons/point_of_sale/static/tests/tours/point_of_sale.js
Expand Up @@ -55,7 +55,7 @@ odoo.define('point_of_sale.tour.pricelist', function (require) {
var product_desk_pad = posmodel.db.search_product_in_category(0, 'Desk Pad')[0];
var product_letter_tray = posmodel.db.search_product_in_category(0, 'Letter Tray')[0];
var product_whiteboard = posmodel.db.search_product_in_category(0, 'Whiteboard')[0];
var product_miscellaneous = posmodel.db.search_product_in_category(0, 'Miscellaneous')[0];
var product_miscellaneous = posmodel.db.search_product_in_category(0, 'Discount')[0];

compare_backend_frontend(product_letter_tray, 'Public Pricelist', 0, undefined)()
.then(compare_backend_frontend(product_letter_tray, 'Public Pricelist', 1, undefined))
Expand Down Expand Up @@ -107,7 +107,7 @@ odoo.define('point_of_sale.tour.pricelist', function (require) {
trigger: ".selection-item:contains('Fixed')",
}, {
content: "prices should be updated in the product screen",
trigger: ".product:contains('Miscellaneous'):contains('$ 1.00')",
trigger: ".product:contains('Discount'):contains('$ 1.00')",
run: function () {}, // it's a check
}, {
content: "open customer list",
Expand All @@ -130,7 +130,7 @@ odoo.define('point_of_sale.tour.pricelist', function (require) {
trigger: ".button.cancel:visible",
}, {
content: "prices should be updated in the product screen",
trigger: ".product:contains('Miscellaneous'):contains('$ 18.00')",
trigger: ".product:contains('Discount'):contains('$ 0.00')",
run: function () {}, // it's a check
}, {
content: "open customer list",
Expand Down Expand Up @@ -196,16 +196,16 @@ shelf have not (their price was manually overridden)",
trigger: ".selection-item:contains('min_quantity ordering')",
}, {
content: "order 1 miscellaneous product",
trigger: ".product:contains('Miscellaneous')",
trigger: ".product:contains('Discount')",
}, {
content: "order 1 miscellaneous product",
trigger: ".product:contains('Miscellaneous')",
trigger: ".product:contains('Discount')",
}, {
content: "order 1 miscellaneous product",
trigger: ".product:contains('Miscellaneous')",
trigger: ".product:contains('Discount')",
}, {
content: "verify there is one line with 3 miscellaneous products",
trigger: ".orderline:contains('Miscellaneous') em:contains('3.000')",
trigger: ".orderline:contains('Discount') em:contains('3.000')",
run: function () {}, // it's a check
}, {
content: "close the Point of Sale frontend",
Expand Down
23 changes: 11 additions & 12 deletions addons/pos_discount/models/pos_config.py
Expand Up @@ -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()
4 changes: 4 additions & 0 deletions addons/pos_discount/views/pos_discount_views.xml
Expand Up @@ -17,4 +17,8 @@
</div>
</field>
</record>

<data noupdate="1">
<function model="pos.config" name="_default_discount_value_on_module_install"/>
</data>
</odoo>

0 comments on commit 0c067f5

Please sign in to comment.