diff --git a/pos_dynamic_price/static/src/js/helper.js b/pos_dynamic_price/static/src/js/helper.js deleted file mode 100644 index b5a22eb2..00000000 --- a/pos_dynamic_price/static/src/js/helper.js +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** -* Point Of Sale - Dynamic Price for POS Odoo -* Copyright (C) 2014 Taktik (http://www.taktik.be) -* @author Adil Houmadi -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see . -* -******************************************************************************/ -Object.size = function (obj) { - "use strict"; - var size = 0, key; - for (key in obj) { - if (obj.hasOwnProperty(key)) { - size += 1; - } - } - return size; -}; \ No newline at end of file diff --git a/pos_dynamic_price/view/pos_dynamic_price_template.xml b/pos_dynamic_price/view/pos_dynamic_price_template.xml deleted file mode 100644 index 5f9f7b8c..00000000 --- a/pos_dynamic_price/view/pos_dynamic_price_template.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - diff --git a/pos_dynamic_price/README.md b/pos_pricelist/README.rst similarity index 92% rename from pos_dynamic_price/README.md rename to pos_pricelist/README.rst index 16d4c188..ea046571 100644 --- a/pos_dynamic_price/README.md +++ b/pos_pricelist/README.rst @@ -21,7 +21,8 @@ This module loads all the necessary data into the POS in order to have a coheren - Attached pricelist on partner will take effect on the POS, which means that if we attach a pricelist to a partner. The POS will recognize it and will compute the price according to the rule defined. -- Fiscal Position of each partner will also be present so taxes will be correctly computed (conforming to the fiscal position). +- Fiscal Position of each partner will also be present so taxes will be correctly computed +(conforming to the fiscal position). - Implemented Rules are : 1. (-1) : Rule based on other pricelist
@@ -30,5 +31,4 @@ The POS will recognize it and will compute the price according to the rule defin ### Missing features : -- As you may know, product template is not fully implemented in the POS, so I decided to drop it from -this module. \ No newline at end of file +- As you may know, product template is not fully implemented in the POS, so I decided to drop it from this module. \ No newline at end of file diff --git a/pos_dynamic_price/__init__.py b/pos_pricelist/__init__.py similarity index 95% rename from pos_dynamic_price/__init__.py rename to pos_pricelist/__init__.py index 80169306..6d755589 100644 --- a/pos_dynamic_price/__init__.py +++ b/pos_pricelist/__init__.py @@ -1,6 +1,6 @@ # -#- coding: utf-8 -#- ############################################################################## -# Point Of Sale - Dynamic Price for POS Odoo +# Point Of Sale - Pricelist for POS Odoo # Copyright (C) 2014 Taktik (http://www.taktik.be) # @author Adil Houmadi # diff --git a/pos_dynamic_price/__openerp__.py b/pos_pricelist/__openerp__.py similarity index 86% rename from pos_dynamic_price/__openerp__.py rename to pos_pricelist/__openerp__.py index 755ce6f9..d254085b 100644 --- a/pos_dynamic_price/__openerp__.py +++ b/pos_pricelist/__openerp__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# Point Of Sale - Dynamic Price for POS Odoo +# Point Of Sale - Pricelist for POS Odoo # Copyright (C) 2014 Taktik (http://www.taktik.be) # @author Adil Houmadi # @@ -17,22 +17,22 @@ # ############################################################################## { - 'name': 'POS Dynamic Price', + 'name': 'POS Pricelist', 'version': '1.0.0', 'category': 'Point Of Sale', 'sequence': 1, 'author': 'Adil Houmadi @Taktik', - 'summary': 'Dyanmic Price Point of sale', + 'summary': 'Pricelist for Point of sale', 'description': """ New features for the Point Of Sale: ============================================= - Dynamic price on the point of sale + Add support for pricelist on the point of sale """, 'depends': [ "point_of_sale", ], 'data': [ - "view/pos_dynamic_price_template.xml", + "views/pos_pricelist_template.xml", ], 'installable': True, 'application': False, diff --git a/pos_dynamic_price/static/src/js/db.js b/pos_pricelist/static/src/js/db.js similarity index 71% rename from pos_dynamic_price/static/src/js/db.js rename to pos_pricelist/static/src/js/db.js index da160bf8..9e5e2715 100644 --- a/pos_dynamic_price/static/src/js/db.js +++ b/pos_pricelist/static/src/js/db.js @@ -1,5 +1,5 @@ /****************************************************************************** -* Point Of Sale - Dynamic Price for POS Odoo +* Point Of Sale - Pricelist for POS Odoo * Copyright (C) 2014 Taktik (http://www.taktik.be) * @author Adil Houmadi * @@ -15,7 +15,9 @@ * along with this program. If not, see . * ******************************************************************************/ -function pdp_db(instance, module) { +function pos_pricelist_db(instance, module) { + + console.log('Loading ...'); module.PosDB = module.PosDB.extend({ init: function (options) { @@ -26,9 +28,9 @@ function pdp_db(instance, module) { this.pricelist_version_by_id = {}; this.pricelist_item_by_id = {}; this.pricelist_item_sorted = []; - this.product_catrgory_by_id = {}; - this.product_catrgory_children = {}; - this.product_catrgory_ancestors = {}; + this.product_category_by_id = {}; + this.product_category_children = {}; + this.product_category_ancestors = {}; this.product_price_type_by_id = {}; this.supplierinfo_by_id = {}; this.pricelist_partnerinfo_by_id = {}; @@ -38,8 +40,8 @@ function pdp_db(instance, module) { if (!(fiscal_position_taxes instanceof Array)) { fiscal_position_taxes = [fiscal_position_taxes]; } - for (var i = 0, len = fiscal_position_taxes.length; i < len; i++) { - var fiscal_position_tax = fiscal_position_taxes[i]; + var fiscal_position_tax; + while (fiscal_position_tax = fiscal_position_taxes.pop()) { this.fiscal_position_tax_by_id[fiscal_position_tax.id] = fiscal_position_tax; } }, @@ -47,8 +49,8 @@ function pdp_db(instance, module) { if (!(pricelist_partnerinfos instanceof Array)) { pricelist_partnerinfos = [pricelist_partnerinfos]; } - for (var i = 0, len = pricelist_partnerinfos.length; i < len; i++) { - var partner_info = pricelist_partnerinfos[i]; + var partner_info; + while (partner_info = pricelist_partnerinfos.pop()) { this.pricelist_partnerinfo_by_id[partner_info.id] = partner_info; } }, @@ -56,8 +58,8 @@ function pdp_db(instance, module) { if (!(supplierinfos instanceof Array)) { supplierinfos = [supplierinfos]; } - for (var i = 0, len = supplierinfos.length; i < len; i++) { - var supplier_info = supplierinfos[i]; + var supplier_info; + while (supplier_info = supplierinfos.pop()) { this.supplierinfo_by_id[supplier_info.id] = supplier_info; } }, @@ -70,8 +72,8 @@ function pdp_db(instance, module) { if (!(pricelists instanceof Array)) { pricelists = [pricelists]; } - for (var i = 0, len = pricelists.length; i < len; i++) { - var pricelist = pricelists[i]; + var pricelist; + while (pricelist = pricelists.pop()) { this.pricelist_by_id[pricelist.id] = pricelist; } }, @@ -79,8 +81,8 @@ function pdp_db(instance, module) { if (!(versions instanceof Array)) { versions = [versions]; } - for (var i = 0, len = versions.length; i < len; i++) { - var version = versions[i]; + var version; + while (version = versions.pop()) { this.pricelist_version_by_id[version.id] = version; } }, @@ -88,8 +90,8 @@ function pdp_db(instance, module) { if (!(items instanceof Array)) { items = [items]; } - for (var i = 0, len = items.length; i < len; i++) { - var item = items[i]; + var item; + while (item = items.pop()) { this.pricelist_item_by_id[item.id] = item; } this.pricelist_item_sorted = this._items_sorted(); @@ -98,33 +100,32 @@ function pdp_db(instance, module) { if (!(price_types instanceof Array)) { price_types = [price_types]; } - for (var i = 0, len = price_types.length; i < len; i++) { - var ptype = price_types[i]; + var ptype; + while (ptype = price_types.pop()) { this.product_price_type_by_id[ptype.id] = ptype; } }, add_product_categories: function (categories) { - var self = this; if (!(categories instanceof Array)) { categories = [categories]; } - for (var i = 0, len = categories.length; i < len; i++) { - var category = categories[i]; - this.product_catrgory_by_id[category.id] = category; - this.product_catrgory_children[category.id] = category.child_id - } - function make_ancestors(cat_id, ancestors) { - self.product_catrgory_ancestors[cat_id] = ancestors; - ancestors = ancestors.slice(0); - ancestors.push(cat_id); - var children = self.product_catrgory_children[cat_id] || []; - for (var i = 0, len = children.length; i < len; i++) { - make_ancestors(children[i], ancestors); - } + var category; + while (category = categories.pop()) { + this.product_category_by_id[category.id] = category; + this.product_category_children[category.id] = category.child_id } - if (categories.length) { - var cat = categories[0]; - make_ancestors(cat.id, cat.parent_id === false ? [] : [cat.parent_id]) + this._make_ancestors(); + }, + _make_ancestors: function () { + var category, ancestors; + for (var id in this.product_category_by_id) { + category = this.product_category_by_id[id]; + ancestors = []; + while (category.parent_id) { + ancestors.push(category.parent_id[0]); + category = category.parent_id ? this.product_category_by_id[category.parent_id[0]] : false; + } + this.product_category_ancestors[parseInt(id)] = ancestors; } }, _items_sorted: function () { @@ -153,4 +154,4 @@ function pdp_db(instance, module) { return taxes; } }) -} \ No newline at end of file +} diff --git a/pos_dynamic_price/static/src/js/main.js b/pos_pricelist/static/src/js/main.js similarity index 78% rename from pos_dynamic_price/static/src/js/main.js rename to pos_pricelist/static/src/js/main.js index dcf31eed..143d36e0 100644 --- a/pos_dynamic_price/static/src/js/main.js +++ b/pos_pricelist/static/src/js/main.js @@ -1,5 +1,5 @@ /****************************************************************************** -* Point Of Sale - Dynamic Price for POS Odoo +* Point Of Sale - Pricelist for POS Odoo * Copyright (C) 2014 Taktik (http://www.taktik.be) * @author Adil Houmadi * @@ -15,9 +15,10 @@ * along with this program. If not, see . * ******************************************************************************/ -openerp.pos_dynamic_price = function (instance) { +openerp.pos_pricelist = function (instance) { var module = instance.point_of_sale; - pdp_db(instance, module); - pdp_models(instance, module); - pdp_screens(instance, module); -}; \ No newline at end of file + pos_pricelist_db(instance, module); + pos_pricelist_models(instance, module); + pos_pricelist_screens(instance, module); + pos_pricelist_widgets(instance, module); +}; diff --git a/pos_dynamic_price/static/src/js/models.js b/pos_pricelist/static/src/js/models.js similarity index 94% rename from pos_dynamic_price/static/src/js/models.js rename to pos_pricelist/static/src/js/models.js index 7f56a8d0..e87b5e73 100644 --- a/pos_dynamic_price/static/src/js/models.js +++ b/pos_pricelist/static/src/js/models.js @@ -1,5 +1,5 @@ /****************************************************************************** -* Point Of Sale - Dynamic Price for POS Odoo +* Point Of Sale - Pricelist for POS Odoo * Copyright (C) 2014 Taktik (http://www.taktik.be) * @author Adil Houmadi * @@ -15,7 +15,7 @@ * along with this program. If not, see . * ******************************************************************************/ -function pdp_models(instance, module) { +function pos_pricelist_models(instance, module) { var _t = instance.web._t; var round_pr = instance.web.round_precision @@ -58,9 +58,6 @@ function pdp_models(instance, module) { * Extend the order */ module.Order = module.Order.extend({ - initialize: function (attributes) { - this._super('initialize', attributes); - }, /** * override this method to merge lines * TODO : find a better way to do it @@ -111,6 +108,7 @@ function pdp_models(instance, module) { module.Orderline = module.Orderline.extend({ initialize: function (attr, options) { this._super('initialize', attr, options); + this.manuel_price = false; if (options.product !== undefined) { var qty = this.compute_qty(options.order, options.product); var partner = options.order.get_client(); @@ -122,6 +120,12 @@ function pdp_models(instance, module) { } } }, + /** + * @param state + */ + set_manuel_price: function (state) { + this.manuel_price = state; + }, /** * @param quantity */ @@ -235,13 +239,15 @@ function pdp_models(instance, module) { * @returns {boolean} */ can_be_merged_with: function (orderline) { - if (this.get_product().id !== orderline.get_product().id) { - return false; - } else if (!this.get_unit()) { - return false; - } else if (this.get_product_type() !== orderline.get_product_type()) { - return false; - } else return this.get_discount() <= 0; + var result = this._super('can_be_merged_with', orderline); + if(!result) { + if(!this.manuel_price) { + return (this.get_product().id === orderline.get_product().id); + } else { + return false; + } + } + return true; }, /** * Override to set price @@ -263,7 +269,7 @@ function pdp_models(instance, module) { orderlines = order.get('orderLines').models; } for (var i = 0; i < orderlines.length; i++) { - if (orderlines[i].product.id === product.id) { + if (orderlines[i].product.id === product.id && !orderlines[i].manuel_price) { qty += orderlines[i].quantity; } } @@ -299,7 +305,7 @@ function pdp_models(instance, module) { * @returns {boolean} */ compute_price: function (database, product, partner, qty, pricelist_id) { - debugger; + var self = this; var db = database; @@ -316,12 +322,12 @@ function pdp_models(instance, module) { var categ_ids = []; if (product.categ_id) { categ_ids.push(product.categ_id[0]); - categ_ids = categ_ids.concat(db.product_catrgory_ancestors[product.categ_id[0]]); + categ_ids = categ_ids.concat(db.product_category_ancestors[product.categ_id[0]]); } // find items - var items = [], i; - for (var i = 0, len = db.pricelist_item_sorted.length; i < len; i++) { + var items = [], i, len; + for (i = 0, len = db.pricelist_item_sorted.length; i < len; i++) { var item = db.pricelist_item_sorted[i]; if ((item.product_id === false || item.product_id[0] === product.id) && (item.categ_id === false || categ_ids.indexOf(item.categ_id[0]) !== -1) && @@ -336,7 +342,7 @@ function pdp_models(instance, module) { var price = false; // loop through items - for (var i = 0, len = items.length; i < len; i++) { + for (i = 0, len = items.length; i < len; i++) { var rule = items[i]; if (rule.min_quantity && qty < rule.min_quantity) { @@ -351,7 +357,7 @@ function pdp_models(instance, module) { if (cat_id == rule.categ_id[0]) { break; } - cat_id = db.product_catrgory_by_id[cat_id].parent_id[0]; + cat_id = db.product_category_by_id[cat_id].parent_id[0]; } if (!(cat_id)) { continue; @@ -435,13 +441,13 @@ function pdp_models(instance, module) { function arrange_elements(pos_model) { var product_model = pos_model.find_model('product.product'); - if (Object.size(product_model) == 1) { + if (_.size(product_model) == 1) { var product_index = parseInt(Object.keys(product_model)[0]); pos_model.models[product_index].fields.push('categ_id', 'seller_ids'); } var res_product_pricelist = pos_model.find_model('product.pricelist'); - if (Object.size(res_product_pricelist) == 1) { + if (_.size(res_product_pricelist) == 1) { var pricelist_index = parseInt(Object.keys(res_product_pricelist)[0]); // after the pricelist we can load all pricelists, versions and items @@ -536,11 +542,11 @@ function pdp_models(instance, module) { } var res_partner_model = pos_model.find_model('res.partner'); - if (Object.size(res_partner_model) == 1) { + if (_.size(res_partner_model) == 1) { var res_partner_index = parseInt(Object.keys(res_partner_model)[0]); pos_model.models[res_partner_index].fields.push('property_account_position', 'property_product_pricelist'); } } -} \ No newline at end of file +} diff --git a/pos_dynamic_price/static/src/js/screens.js b/pos_pricelist/static/src/js/screens.js similarity index 95% rename from pos_dynamic_price/static/src/js/screens.js rename to pos_pricelist/static/src/js/screens.js index e2d088d0..b2d674ec 100644 --- a/pos_dynamic_price/static/src/js/screens.js +++ b/pos_pricelist/static/src/js/screens.js @@ -1,5 +1,5 @@ /****************************************************************************** -* Point Of Sale - Dynamic Price for POS Odoo +* Point Of Sale - Pricelist for POS Odoo * Copyright (C) 2014 Taktik (http://www.taktik.be) * @author Adil Houmadi * @@ -15,7 +15,7 @@ * along with this program. If not, see . * ******************************************************************************/ -function pdp_screens(instance, module) { +function pos_pricelist_screens(instance, module) { module.ClientListScreenWidget = module.ClientListScreenWidget.extend({ save_changes: function () { diff --git a/pos_pricelist/static/src/js/widgets.js b/pos_pricelist/static/src/js/widgets.js new file mode 100644 index 00000000..14390ce3 --- /dev/null +++ b/pos_pricelist/static/src/js/widgets.js @@ -0,0 +1,33 @@ +/****************************************************************************** + * Point Of Sale - Pricelist for POS Odoo + * Copyright (C) 2014 Taktik (http://www.taktik.be) + * @author Adil Houmadi + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + ******************************************************************************/ +function pos_pricelist_widgets(instance, module) { + + module.OrderWidget = module.OrderWidget.extend({ + set_value: function (val) { + this._super(val); + var order = this.pos.get('selectedOrder'); + if (this.editable && order.getSelectedLine()) { + var mode = this.numpad_state.get('mode'); + if (mode === 'price') { + order.getSelectedLine().set_manuel_price(true); + } + } + } + }); +} + diff --git a/pos_pricelist/views/pos_pricelist_template.xml b/pos_pricelist/views/pos_pricelist_template.xml new file mode 100644 index 00000000..eaa794a8 --- /dev/null +++ b/pos_pricelist/views/pos_pricelist_template.xml @@ -0,0 +1,29 @@ + + + + + + + +