18
18
function pos_pricelist_models ( instance , module ) {
19
19
20
20
var _t = instance . web . _t ;
21
- var round_pr = instance . web . round_precision
21
+ var round_pr = instance . web . round_precision ;
22
22
23
23
/**
24
24
* @param funcName
@@ -60,7 +60,8 @@ function pos_pricelist_models(instance, module) {
60
60
module . Order = module . Order . extend ( {
61
61
/**
62
62
* 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
64
65
* @param product
65
66
* @param options
66
67
*/
@@ -101,7 +102,6 @@ function pos_pricelist_models(instance, module) {
101
102
this . selectLine ( this . getLastOrderline ( ) ) ;
102
103
}
103
104
} ) ;
104
-
105
105
/**
106
106
* Extend the Order line
107
107
*/
@@ -143,6 +143,7 @@ function pos_pricelist_models(instance, module) {
143
143
/**
144
144
* override this method to take fiscal postions in consideration
145
145
* get all price
146
+ * TODO : find a better way to do it : need some refactoring in the pos standard
146
147
* @returns {{priceWithTax: *, priceWithoutTax: *, tax: number, taxDetails: {}} }
147
148
*/
148
149
get_all_prices : function ( ) {
@@ -153,32 +154,39 @@ function pos_pricelist_models(instance, module) {
153
154
var totalTax = base ;
154
155
var totalNoTax = base ;
155
156
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
156
162
var partner = this . order . get_client ( ) ;
157
- var taxes_ids = product . taxes_id ;
158
163
var fiscal_position_taxes = [ ] ;
159
164
if ( partner && partner . property_account_position ) {
160
165
fiscal_position_taxes = self . pos . db . find_taxes_by_fiscal_position_id ( partner . property_account_position [ 0 ] ) ;
161
166
}
162
- var product_taxes_ids = [ ] ;
167
+ var product_taxes = [ ] ;
163
168
for ( var i = 0 , ilen = fiscal_position_taxes . length ; i < ilen ; i ++ ) {
164
169
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 ) ;
169
177
}
170
178
}
171
179
}
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
+ }
174
188
}
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 ) {
182
190
if ( tax . price_include ) {
183
191
var tmp ;
184
192
if ( tax . type === "percent" ) {
@@ -202,6 +210,9 @@ function pos_pricelist_models(instance, module) {
202
210
throw "This type of tax is not supported by the point of sale: " + tax . type ;
203
211
}
204
212
tmp = round_pr ( tmp , currency_rounding ) ;
213
+ if ( tax . include_base_amount ) {
214
+ base += tmp ;
215
+ }
205
216
taxtotal += tmp ;
206
217
totalTax += tmp ;
207
218
taxdetail [ tax . id ] = tmp ;
@@ -214,7 +225,6 @@ function pos_pricelist_models(instance, module) {
214
225
"taxDetails" : taxdetail
215
226
} ;
216
227
} ,
217
-
218
228
/**
219
229
* compute price for all price list
220
230
* @param db
@@ -240,8 +250,8 @@ function pos_pricelist_models(instance, module) {
240
250
*/
241
251
can_be_merged_with : function ( orderline ) {
242
252
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 ) {
245
255
return ( this . get_product ( ) . id === orderline . get_product ( ) . id ) ;
246
256
} else {
247
257
return false ;
@@ -422,7 +432,7 @@ function pos_pricelist_models(instance, module) {
422
432
} ) ;
423
433
424
434
/**
425
- * show error based on pop up
435
+ * show error
426
436
* @param context
427
437
* @param message
428
438
* @param comment
@@ -449,8 +459,6 @@ function pos_pricelist_models(instance, module) {
449
459
var res_product_pricelist = pos_model . find_model ( 'product.pricelist' ) ;
450
460
if ( _ . size ( res_product_pricelist ) == 1 ) {
451
461
var pricelist_index = parseInt ( Object . keys ( res_product_pricelist ) [ 0 ] ) ;
452
-
453
- // after the pricelist we can load all pricelists, versions and items
454
462
pos_model . models . splice ( ++ pricelist_index , 0 ,
455
463
{
456
464
model : 'account.fiscal.position.tax' ,
@@ -535,6 +543,17 @@ function pos_pricelist_models(instance, module) {
535
543
fields : [ 'name' , 'field' , 'currency_id' ] ,
536
544
domain : null ,
537
545
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
+ }
538
557
self . db . add_price_types ( price_types ) ;
539
558
}
540
559
}
0 commit comments