Browse Source

Aug 17 : [UPDT] Bug Fixed 'pos_product_creation'

pull/277/head
AjmalCybro 2 years ago
parent
commit
f5f7539f5d
  1. 2
      pos_product_creation/controllers/main.py
  2. 52
      pos_product_creation/static/src/js/product_create_button.js
  3. 3
      pos_product_creation/static/src/xml/product_create_popup.xml

2
pos_product_creation/controllers/main.py

@ -33,7 +33,7 @@ class PosProductCreation(http.Controller):
product_category = 'consu' product_category = 'consu'
elif category == 'Service': elif category == 'Service':
product_category = 'service' product_category = 'service'
elif category == 'Stockable': elif category == 'Storable':
product_category = 'product' product_category = 'product'
else: else:
product_category = '' product_category = ''

52
pos_product_creation/static/src/js/product_create_button.js

@ -24,7 +24,24 @@ odoo.define('pos_product_creation.product_create_button', function(require) {
var product_image; var product_image;
var image = $('#product-image')[0].files[0] var image = $('#product-image')[0].files[0]
var reader = new FileReader(); var reader = new FileReader();
await reader.readAsDataURL(image); if (image){
if(image.type == "image/jpeg"){
await reader.readAsDataURL(image);
} else {
// return self.showPopup('ErrorPopup', {
// title: _('Choose Image In JPEG Format'),
// });
return self.showPopup('ErrorPopup', {
title: self.env._t('Filed Error'),
body: self.env._t('Choose Image In JPEG Format.'),
});
}
} else {
return self.showPopup('ErrorPopup', {
title: self.env._t('Empty Filed'),
body: self.env._t('All Fields Are Required.'),
});
}
reader.onload = function(){ reader.onload = function(){
product_image = reader.result product_image = reader.result
var image = product_image.slice(23); var image = product_image.slice(23);
@ -35,17 +52,7 @@ odoo.define('pos_product_creation.product_create_button', function(require) {
var unit_measure = payload[5]; var unit_measure = payload[5];
var product_categories = payload[6]; var product_categories = payload[6];
var barcode = payload[7]; var barcode = payload[7];
if (!product_name){ let datas = {
return self.showPopup('ErrorPopup', {
title: _('Product Name Is Required'),
});
}
if (!unit_measure){
return self.showPopup('ErrorPopup', {
title: _('A Unit Of Measure Is Required'),
});
}
ajax.jsonRpc('/create_product', 'call', {
'category': product_category, 'category': product_category,
'image': image, 'image': image,
'name': product_name, 'name': product_name,
@ -54,8 +61,22 @@ odoo.define('pos_product_creation.product_create_button', function(require) {
'unit_measure': unit_measure, 'unit_measure': unit_measure,
'product_categories': product_categories, 'product_categories': product_categories,
'barcode': barcode, 'barcode': barcode,
}) }
for (const [key, value] of Object.entries(datas)){
if (value === null || value === undefined){
var errorFound = 1;
} else {
let errorFound = 0;
}
}
if (errorFound == 1){
return self.showPopup('ErrorPopup', {
title: self.env._t('Empty Filed'),
body: self.env._t('All Fields Are Required.'),
});
} else {
ajax.jsonRpc('/create_product', 'call', datas)
}
} }
} }
@ -71,6 +92,5 @@ odoo.define('pos_product_creation.product_create_button', function(require) {
}); });
Registries.Component.add(ProductCreateButton); Registries.Component.add(ProductCreateButton);
return ProductCreateButton; return ProductCreateButton;
}); });

3
pos_product_creation/static/src/xml/product_create_popup.xml

@ -54,7 +54,7 @@
<select class="type" style="width: 233px;height:46px" t-model="state.typeValue" <select class="type" style="width: 233px;height:46px" t-model="state.typeValue"
required=""> required="">
<option>Consumable</option> <option>Consumable</option>
<option>Stockable</option> <option>Storable</option>
<option>Service</option> <option>Service</option>
</select> </select>
</div> </div>
@ -85,7 +85,6 @@
<t t-foreach="Object.values(this.env.pos.db.category_by_id)" t-as="item" t-key="item.name"> <t t-foreach="Object.values(this.env.pos.db.category_by_id)" t-as="item" t-key="item.name">
<option t-att-value="item.id" t-esc="item.name"/> <option t-att-value="item.id" t-esc="item.name"/>
</t> </t>
</select> </select>
</div> </div>
</div> </div>

Loading…
Cancel
Save