Skip to content

Commit 2092500

Browse files
author
Adil Houmadi
committed
[ADD] Some functional testing
1 parent 91fc78d commit 2092500

File tree

8 files changed

+382
-30
lines changed

8 files changed

+382
-30
lines changed

pos_pricelist/__openerp__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'author': 'Adil Houmadi @Taktik',
2525
'summary': 'Pricelist for Point of sale',
2626
'description': """
27-
New features for the Point Of Sale:
27+
New feature for the Point Of Sale:
2828
=============================================
2929
Add support for pricelist on the point of sale
3030
""",
@@ -34,6 +34,9 @@
3434
'data': [
3535
"views/pos_pricelist_template.xml",
3636
],
37+
'demo': [
38+
'demo/pos_pricelist_demo.yml',
39+
],
3740
'installable': True,
3841
'application': False,
3942
'auto_install': False,
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-
2+
This product will have two rule (min_qty:3 => 10%, min_qty:5 => 30%)
3+
-
4+
!record {model: product.product, id: pos_product_product_1}:
5+
default_code: ABC123
6+
name: POS Product 1
7+
type: product
8+
categ_id: product.product_category_1
9+
list_price: 100.0
10+
standard_price: 50.0
11+
uom_id: product.product_uom_unit
12+
uom_po_id: product.product_uom_unit
13+
available_in_pos: True
14+
15+
-
16+
This product will have one rule (min_qty:2 => 10%)
17+
-
18+
!record {model: product.product, id: pos_product_product_2}:
19+
default_code: ABC124
20+
name: POS Product 2
21+
type: product
22+
categ_id: product.product_category_1
23+
list_price: 100.0
24+
standard_price: 100.0
25+
uom_id: product.product_uom_unit
26+
uom_po_id: product.product_uom_unit
27+
available_in_pos: True
28+
29+
-
30+
This product will have a rule that (based on supplier discount)
31+
-
32+
!record {model: product.product, id: pos_product_product_3}:
33+
default_code: ABC125
34+
name: POS Product 3
35+
type: product
36+
categ_id: product.product_category_1
37+
list_price: 100.0
38+
standard_price: 50.0
39+
uom_id: product.product_uom_unit
40+
uom_po_id: product.product_uom_unit
41+
available_in_pos: True
42+
seller_ids:
43+
- delay: 1
44+
name: base.res_partner_3
45+
pricelist_ids:
46+
- min_quantity : 2.0
47+
price : 80
48+
49+
-
50+
This product belgon to computer category (5% dicount)
51+
-
52+
!record {model: product.product, id: pos_product_product_4}:
53+
default_code: ABC125
54+
name: POS Product 4
55+
type: product
56+
categ_id: product.product_category_4
57+
list_price: 100.0
58+
standard_price: 50.0
59+
uom_id: product.product_uom_unit
60+
uom_po_id: product.product_uom_unit
61+
available_in_pos: True
62+
-
63+
Prepare pricelist items
64+
-
65+
!record {model: product.pricelist.version, id: product.ver0}:
66+
items_id:
67+
- name: 10% Discount on POS Product 1 (Qty 3)
68+
sequence: 2
69+
product_id: pos_product_product_1
70+
base: 1
71+
price_discount: -0.10
72+
min_quantity: 3
73+
- name: 30% Discount on POS Product 1 (Qty 5)
74+
sequence: 1
75+
product_id: pos_product_product_1
76+
min_quantity: 5
77+
base: 1
78+
price_discount: -0.30
79+
- name: 10% Discount (POS Product 2)
80+
sequence: 1
81+
product_id: pos_product_product_2
82+
base: 2
83+
price_discount: -0.10
84+
min_quantity: 2
85+
- name: 20% Discount given by supplier
86+
sequence: 1
87+
min_quantity: 2
88+
product_id: pos_product_product_3
89+
base: -2
90+
- name: 5% Discount on all Computer related products (Qty 2)
91+
sequence: 1
92+
min_quantity: 2
93+
base: 1
94+
categ_id: product.product_category_4
95+
price_discount: -0.05
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/******************************************************************************
2+
* Point Of Sale - Pricelist for POS Odoo
3+
* Copyright (C) 2014 Taktik (http://www.taktik.be)
4+
* @author Adil Houmadi <[email protected]>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
******************************************************************************/
18+
.popover {
19+
position: absolute;
20+
top: 0;
21+
left: 0;
22+
z-index: 1060;
23+
display: none;
24+
max-width: 276px;
25+
padding: 1px;
26+
text-align: left;
27+
white-space: normal;
28+
background-color: #fff;
29+
-webkit-background-clip: padding-box;
30+
background-clip: padding-box;
31+
border: 1px solid #ccc;
32+
border: 1px solid rgba(0, 0, 0, .2);
33+
border-radius: 6px;
34+
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
35+
box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
36+
}
37+
.popover-title {
38+
padding: 8px 14px;
39+
margin: 0;
40+
font-size: 14px;
41+
font-weight: normal;
42+
line-height: 18px;
43+
background-color: #f7f7f7;
44+
border-bottom: 1px solid #ebebeb;
45+
border-radius: 5px 5px 0 0;
46+
}

pos_pricelist/static/src/js/db.js

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
******************************************************************************/
1818
function pos_pricelist_db(instance, module) {
1919

20-
console.log('Loading ...');
21-
2220
module.PosDB = module.PosDB.extend({
2321
init: function (options) {
2422
options = options || {};

pos_pricelist/static/src/js/models.js

+43-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
function pos_pricelist_models(instance, module) {
1919

2020
var _t = instance.web._t;
21-
var round_pr = instance.web.round_precision
21+
var round_pr = instance.web.round_precision;
2222

2323
/**
2424
* @param funcName
@@ -60,7 +60,8 @@ function pos_pricelist_models(instance, module) {
6060
module.Order = module.Order.extend({
6161
/**
6262
* override this method to merge lines
63-
* TODO : find a better way to do it
63+
* TODO : Need some refactoring in the standard POS to Do it better
64+
* TODO : from line 73 till 85, we need to move this to another method
6465
* @param product
6566
* @param options
6667
*/
@@ -101,7 +102,6 @@ function pos_pricelist_models(instance, module) {
101102
this.selectLine(this.getLastOrderline());
102103
}
103104
});
104-
105105
/**
106106
* Extend the Order line
107107
*/
@@ -143,6 +143,7 @@ function pos_pricelist_models(instance, module) {
143143
/**
144144
* override this method to take fiscal postions in consideration
145145
* get all price
146+
* TODO : find a better way to do it : need some refactoring in the pos standard
146147
* @returns {{priceWithTax: *, priceWithoutTax: *, tax: number, taxDetails: {}}}
147148
*/
148149
get_all_prices: function () {
@@ -153,32 +154,39 @@ function pos_pricelist_models(instance, module) {
153154
var totalTax = base;
154155
var totalNoTax = base;
155156
var product = this.get_product();
157+
var taxes = this.get_applicable_taxes();
158+
var taxtotal = 0;
159+
var taxdetail = {};
160+
161+
// Add by pos_pricelist
156162
var partner = this.order.get_client();
157-
var taxes_ids = product.taxes_id;
158163
var fiscal_position_taxes = [];
159164
if (partner && partner.property_account_position) {
160165
fiscal_position_taxes = self.pos.db.find_taxes_by_fiscal_position_id(partner.property_account_position[0]);
161166
}
162-
var product_taxes_ids = [];
167+
var product_taxes = [];
163168
for (var i = 0, ilen = fiscal_position_taxes.length; i < ilen; i++) {
164169
var fp_tax = fiscal_position_taxes[i];
165-
for (var j = 0, jlen = taxes_ids.length; j < jlen; j++) {
166-
var p_tax = taxes_ids[j];
167-
if (fp_tax && p_tax && fp_tax.tax_src_id[0] === p_tax) {
168-
product_taxes_ids.push(fp_tax.tax_dest_id[0]);
170+
for (var j = 0, jlen = taxes.length; j < jlen; j++) {
171+
var p_tax = taxes[j];
172+
if (fp_tax && p_tax && fp_tax.tax_src_id[0] === p_tax.id) {
173+
var dest_tax = _.detect(this.pos.taxes, function (t) {
174+
return t.id === fp_tax.tax_dest_id[0];
175+
});
176+
product_taxes.push(dest_tax);
169177
}
170178
}
171179
}
172-
if (product_taxes_ids.length === 0) {
173-
product_taxes_ids = taxes_ids;
180+
if (product_taxes.length === 0) {
181+
for (var i = 0, ilen = product.taxes_id; i < ilen; i++) {
182+
var _id = product.taxes_id[i];
183+
var p_tax = _.detect(this.pos.taxes, function (t) {
184+
return t.id === _id;
185+
});
186+
product_taxes.push(p_tax);
187+
}
174188
}
175-
var taxes = self.pos.taxes;
176-
var taxtotal = 0;
177-
var taxdetail = {};
178-
_.each(product_taxes_ids, function (el) {
179-
var tax = _.detect(taxes, function (t) {
180-
return t.id === el;
181-
});
189+
_.each(product_taxes, function (tax) {
182190
if (tax.price_include) {
183191
var tmp;
184192
if (tax.type === "percent") {
@@ -202,6 +210,9 @@ function pos_pricelist_models(instance, module) {
202210
throw "This type of tax is not supported by the point of sale: " + tax.type;
203211
}
204212
tmp = round_pr(tmp, currency_rounding);
213+
if (tax.include_base_amount) {
214+
base += tmp;
215+
}
205216
taxtotal += tmp;
206217
totalTax += tmp;
207218
taxdetail[tax.id] = tmp;
@@ -214,7 +225,6 @@ function pos_pricelist_models(instance, module) {
214225
"taxDetails": taxdetail
215226
};
216227
},
217-
218228
/**
219229
* compute price for all price list
220230
* @param db
@@ -240,8 +250,8 @@ function pos_pricelist_models(instance, module) {
240250
*/
241251
can_be_merged_with: function (orderline) {
242252
var result = this._super('can_be_merged_with', orderline);
243-
if(!result) {
244-
if(!this.manuel_price) {
253+
if (!result) {
254+
if (!this.manuel_price) {
245255
return (this.get_product().id === orderline.get_product().id);
246256
} else {
247257
return false;
@@ -422,7 +432,7 @@ function pos_pricelist_models(instance, module) {
422432
});
423433

424434
/**
425-
* show error based on pop up
435+
* show error
426436
* @param context
427437
* @param message
428438
* @param comment
@@ -449,8 +459,6 @@ function pos_pricelist_models(instance, module) {
449459
var res_product_pricelist = pos_model.find_model('product.pricelist');
450460
if (_.size(res_product_pricelist) == 1) {
451461
var pricelist_index = parseInt(Object.keys(res_product_pricelist)[0]);
452-
453-
// after the pricelist we can load all pricelists, versions and items
454462
pos_model.models.splice(++pricelist_index, 0,
455463
{
456464
model: 'account.fiscal.position.tax',
@@ -535,6 +543,17 @@ function pos_pricelist_models(instance, module) {
535543
fields: ['name', 'field', 'currency_id'],
536544
domain: null,
537545
loaded: function (self, price_types) {
546+
// we need to add price type field to product.product model if not the case
547+
var product_model = posmodel.find_model('product.product');
548+
for(var i = 0, len = price_types.length; i < len; i++) {
549+
var p_type = price_types[i].field;
550+
if (_.size(product_model) == 1) {
551+
var product_index = parseInt(Object.keys(product_model)[0]);
552+
if(posmodel.models[product_index].fields.indexOf(p_type) === -1) {
553+
posmodel.models[product_index].fields.push(p_type);
554+
}
555+
}
556+
}
538557
self.db.add_price_types(price_types);
539558
}
540559
}

0 commit comments

Comments
 (0)