1 changed files with 45 additions and 45 deletions
@ -1,53 +1,53 @@ |
|||||
odoo.define('pos_low_sales_price.validation', function(require) { |
odoo.define('pos_low_sales_price.validation', function(require) { |
||||
'use strict'; |
'use strict'; |
||||
const PaymentScreen = require('point_of_sale.PaymentScreen'); |
const PaymentScreen = require('point_of_sale.PaymentScreen'); |
||||
const Registries = require('point_of_sale.Registries'); |
const Registries = require('point_of_sale.Registries'); |
||||
// Created new class validation that extends PaymentScreen and overrides the validateOrder
|
|
||||
const validation = PaymentScreen => |
// Created new class validation that extends PaymentScreen and overrides the validateOrder
|
||||
class extends PaymentScreen { |
const validation = PaymentScreen => |
||||
async validateOrder(isForceValidate) { |
class extends PaymentScreen { |
||||
var self = this |
async validateOrder(isForceValidate) { |
||||
var condition = true |
var self = this; |
||||
var flag = true |
var product_list = []; |
||||
var normal_flow = false |
var orderlines = this.env.pos.selectedOrder.orderlines; |
||||
var number = 1 |
|
||||
var orderlines = this.env.pos.selectedOrder.orderlines |
|
||||
// Checking condition for each orderlines
|
|
||||
for (const lines of orderlines) { |
|
||||
if (lines.product.lst_price < lines.product.standard_price || lines.price < lines.product.standard_price) { |
|
||||
condition = false; |
|
||||
const { confirmed } = await self.showPopup('ConfirmPopup', { |
|
||||
title: 'Alert', |
|
||||
body: 'The Sales Price of ' + lines.product.display_name + |
|
||||
' is less than the Cost Price. Do you want to continue validation?', |
|
||||
}); |
|
||||
if (confirmed) { |
|
||||
// Set flag to false if popup is confirmed
|
|
||||
if (orderlines.length === number) { |
|
||||
flag = false; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
else{ |
|
||||
// Set normal_flow to true if there is no pop-up
|
|
||||
normal_flow = true |
|
||||
|
|
||||
|
// Checking condition for each order line
|
||||
|
for (const line of orderlines) { |
||||
|
if (line.product.lst_price < line.product.standard_price || line.price < line.product.standard_price) { |
||||
|
product_list.push("'" + line.product.display_name + "'"); |
||||
} |
} |
||||
number = number + 1 |
|
||||
} |
} |
||||
|
|
||||
|
if (product_list.length > 0) { |
||||
|
var content = ''; |
||||
|
|
||||
if (normal_flow == true){ |
if (product_list.length === 1) { |
||||
// Order validation for normal flow
|
content = 'The Sales Price of ' + product_list.join(' ') + |
||||
super.validateOrder(isForceValidate); |
' is less than the Cost Price. Do you want to continue validation?'; |
||||
} |
} else { |
||||
if (flag==false && condition== false && normal_flow== false){ |
var lastIndex = product_list.length - 1; |
||||
// Order validation for low price product after confirming the pop-up
|
product_list[lastIndex] = "and " + product_list[lastIndex]; |
||||
super.validateOrder(isForceValidate); |
content = 'The Sales Prices of ' + product_list.join(', ') + |
||||
} |
' are less than the Cost Price. Do you want to continue validation?'; |
||||
|
} |
||||
|
|
||||
|
const { confirmed } = await self.showPopup('ConfirmPopup', { |
||||
|
title: 'Alert', |
||||
|
body: content, |
||||
|
}); |
||||
|
|
||||
} |
if (confirmed) { |
||||
|
super.validateOrder(isForceValidate); |
||||
|
} |
||||
|
} else { |
||||
|
super.validateOrder(isForceValidate); |
||||
|
} |
||||
|
} |
||||
}; |
}; |
||||
Registries.Component.extend(PaymentScreen, validation); |
|
||||
return PaymentScreen; |
Registries.Component.extend(PaymentScreen, validation); |
||||
}); |
return PaymentScreen; |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
|
||||
|
Loading…
Reference in new issue