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 | |
| 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>
| -rw-r--r-- | addons/point_of_sale/data/point_of_sale_data.xml | 12 | ||||
| -rw-r--r-- | addons/point_of_sale/static/img/product_product_49-image.jpg | bin | 14912 -> 0 bytes | |||
| -rw-r--r-- | addons/point_of_sale/static/tests/tours/point_of_sale.js | 14 | ||||
| -rw-r--r-- | addons/pos_discount/models/pos_config.py | 23 | ||||
| -rw-r--r-- | addons/pos_discount/views/pos_discount_views.xml | 4 |
5 files changed, 28 insertions, 25 deletions
diff --git a/addons/point_of_sale/data/point_of_sale_data.xml b/addons/point_of_sale/data/point_of_sale_data.xml index 58a70c4cc87..aaf8008c0a4 100644 --- a/addons/point_of_sale/data/point_of_sale_data.xml +++ b/addons/point_of_sale/data/point_of_sale_data.xml @@ -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"> diff --git a/addons/point_of_sale/static/img/product_product_49-image.jpg b/addons/point_of_sale/static/img/product_product_49-image.jpg Binary files differdeleted file mode 100644 index 5aa7c3278bb..00000000000 --- a/addons/point_of_sale/static/img/product_product_49-image.jpg +++ /dev/null diff --git a/addons/point_of_sale/static/tests/tours/point_of_sale.js b/addons/point_of_sale/static/tests/tours/point_of_sale.js index 4f0a774ff09..77890a56b5a 100644 --- a/addons/point_of_sale/static/tests/tours/point_of_sale.js +++ b/addons/point_of_sale/static/tests/tours/point_of_sale.js @@ -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)) @@ -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", @@ -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", @@ -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", 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> |
