Browse Source

[CHG] : Rename README to README.rst (https://github.com/OCA/pos/pull/6#issuecomment-66383621)

[CHG] : Rename module to pos_pricelist instead of the old one
[FIX] : Fix typo mentioned on this comments :
 - https://github.com/OCA/pos/pull/6#discussion_r21574900
 - https://github.com/OCA/pos/pull/6#commitcomment-9012800
[IMP] : Recover a missed feature while setting a price for an orderline https://github.com/OCA/pos/pull/6#discussion_r21575474
[IMP] : Switch to while loop while iterating over an array
[REM] : Avoid bad practice on Object Class : https://github.com/OCA/pos/pull/6#commitcomment-9012727
pull/6/head
Adil Houmadi 10 years ago
parent
commit
91fc78d2ab
  1. 27
      pos_dynamic_price/static/src/js/helper.js
  2. 20
      pos_dynamic_price/view/pos_dynamic_price_template.xml
  3. 6
      pos_pricelist/README.rst
  4. 2
      pos_pricelist/__init__.py
  5. 10
      pos_pricelist/__openerp__.py
  6. 75
      pos_pricelist/static/src/js/db.js
  7. 13
      pos_pricelist/static/src/js/main.js
  8. 52
      pos_pricelist/static/src/js/models.js
  9. 4
      pos_pricelist/static/src/js/screens.js
  10. 33
      pos_pricelist/static/src/js/widgets.js
  11. 29
      pos_pricelist/views/pos_pricelist_template.xml

27
pos_dynamic_price/static/src/js/helper.js

@ -1,27 +0,0 @@
/******************************************************************************
* Point Of Sale - Dynamic Price for POS Odoo
* Copyright (C) 2014 Taktik (http://www.taktik.be)
* @author Adil Houmadi <ah@taktik.be>
*
* 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 <http://www.gnu.org/licenses/>.
*
******************************************************************************/
Object.size = function (obj) {
"use strict";
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
size += 1;
}
}
return size;
};

20
pos_dynamic_price/view/pos_dynamic_price_template.xml

@ -1,20 +0,0 @@
<openerp>
<data>
<template id="pos_dynamic_price_assets_backend"
name="pos_dynamic_price_assets_backend"
inherit_id="point_of_sale.assets_backend">
<xpath expr="." position="inside">
<script src="/pos_dynamic_price/static/src/js/helper.js"
type="text/javascript"></script>
<script src="/pos_dynamic_price/static/src/js/db.js"
type="text/javascript"></script>
<script src="/pos_dynamic_price/static/src/js/models.js"
type="text/javascript"></script>
<script src="/pos_dynamic_price/static/src/js/screens.js"
type="text/javascript"></script>
<script src="/pos_dynamic_price/static/src/js/main.js"
type="text/javascript"></script>
</xpath>
</template>
</data>
</openerp>

6
pos_dynamic_price/README.md → 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<br/>
@ -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.
- As you may know, product template is not fully implemented in the POS, so I decided to drop it from this module.

2
pos_dynamic_price/__init__.py → 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 <ah@taktik.be>
#

10
pos_dynamic_price/__openerp__.py → 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 <ah@taktik.be>
#
@ -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,

75
pos_dynamic_price/static/src/js/db.js → 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 <ah@taktik.be>
*
@ -15,7 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
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;
}
})
}
}

13
pos_dynamic_price/static/src/js/main.js → 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 <ah@taktik.be>
*
@ -15,9 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
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);
};
pos_pricelist_db(instance, module);
pos_pricelist_models(instance, module);
pos_pricelist_screens(instance, module);
pos_pricelist_widgets(instance, module);
};

52
pos_dynamic_price/static/src/js/models.js → 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 <ah@taktik.be>
*
@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
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');
}
}
}
}

4
pos_dynamic_price/static/src/js/screens.js → 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 <ah@taktik.be>
*
@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
function pdp_screens(instance, module) {
function pos_pricelist_screens(instance, module) {
module.ClientListScreenWidget = module.ClientListScreenWidget.extend({
save_changes: function () {

33
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 <ah@taktik.be>
*
* 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 <http://www.gnu.org/licenses/>.
*
******************************************************************************/
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);
}
}
}
});
}

29
pos_pricelist/views/pos_pricelist_template.xml

@ -0,0 +1,29 @@
<openerp>
<data>
<template id="pos_pricelist_assets_backend"
name="pos_pricelist_assets_backend"
inherit_id="point_of_sale.assets_backend">
<xpath expr="." position="inside">
<script src="/pos_pricelist/static/src/js/db.js"
type="text/javascript"></script>
<script src="/pos_pricelist/static/src/js/models.js"
type="text/javascript"></script>
<script src="/pos_pricelist/static/src/js/widgets.js"
type="text/javascript"></script>
<script src="/pos_pricelist/static/src/js/screens.js"
type="text/javascript"></script>
<script src="/pos_pricelist/static/src/js/tests.js"
type="text/javascript"></script>
<script src="/pos_pricelist/static/src/js/main.js"
type="text/javascript"></script>
</xpath>
</template>
<template id="qunit_suite" name="pos_pricelist_test qunit" inherit_id="web.qunit_suite">
<xpath expr="//head" position="inside">
<script type="text/javascript" src="/pos_pricelist/static/test/tests.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save