Browse Source

Nov 26: [FIX] Bug Fixed 'website_warranty_management'

pull/331/merge
Risvana Cybro 4 weeks ago
parent
commit
c66988588f
  1. 2
      website_warranty_management/__manifest__.py
  2. 6
      website_warranty_management/controllers/website_warranty_management.py
  3. 5
      website_warranty_management/doc/RELEASE_NOTES.md
  4. 174
      website_warranty_management/static/src/js/website_registration.js
  5. 2
      website_warranty_management/views/website_registration_templates.xml

2
website_warranty_management/__manifest__.py

@ -21,7 +21,7 @@
#############################################################################
{
'name': 'Website Warranty Management',
'version': '17.0.1.0.0',
'version': '17.0.1.0.1',
'category': 'Sale',
'summary': 'Warranty management used to manage warranty of product',
'description': """The "Warranty Management" module enables businesses to

6
website_warranty_management/controllers/website_warranty_management.py

@ -38,8 +38,6 @@ class WarrantyClaimController(http.Controller):
'customers': customers,
'products': products})
@http.route('/warranty/claim/submit', type='http', auth="public",
website=True)
def warranty_claim_submit(self):
"""Function to render the claim thanks view"""
@http.route('/warranty/claim/submit', type='http', auth="public", website=True, csrf=True)
def warranty_claim_submit(self, **post):
return request.render('website_warranty_management.claim_thanks_view')

5
website_warranty_management/doc/RELEASE_NOTES.md

@ -4,3 +4,8 @@
#### Version 17.0.1.0.0
#### ADD
- Initial Commit for Warranty Management
#### 18.11.2025
#### Version 17.0.1.0.1
##### UPDT
- Added a feature to automatically create the warranty request in the backend when a request is submitted through the website.

174
website_warranty_management/static/src/js/website_registration.js

@ -3,24 +3,32 @@
import publicWidget from "@web/legacy/js/public/public_widget";
publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({
selector: '.container',
selector: '.warranty-claim-widget',
events: {
'click #customer_id': '_onClickCustomer',
'click #sale_order_id': '_onClickSaleOrder',
'change #customer_id': '_onClickCustomer',
'change #sale_order_id': '_onClickSaleOrder',
'submit #form_submit': '_onSubmit'
},
init() {
this._super(...arguments);
this.orm = this.bindService("orm");
},
async _onClickCustomer(ev) {
ev.preventDefault();
var selectedCustomerId = this.$('#customer_id').val();
if (selectedCustomerId) {
var NameId = parseInt(selectedCustomerId);
await this.orm.call("sale.order", "search_read", [[['partner_id', '=', parseInt(selectedCustomerId)]]]).then(function (result) {
await this.orm.call("sale.order", "search_read", [
[['partner_id', '=', parseInt(selectedCustomerId)], ['is_warranty_check', '=', true]],
['id', 'name']
]).then(function (result) {
var $saleOrderDropdown = $('#sale_order_id');
$saleOrderDropdown.empty();
$saleOrderDropdown.append($('<option>', {
value: '',
text: 'Select Sale Order'
}));
$.each(result, function (i, saleOrder) {
$saleOrderDropdown.append($('<option>', {
value: saleOrder.id,
@ -28,65 +36,143 @@ publicWidget.registry.WarrantyClaim = publicWidget.Widget.extend({
}));
});
});
// Clear products dropdown when customer changes
$('#products_id').empty().append($('<option>', {
value: '',
text: 'Select Product'
}));
}
},
async _onClickSaleOrder(ev) {
ev.preventDefault();
var selectedSaleOrderId = $('#sale_order_id').val();
var $productDropdown = $('#products_id');
if (selectedSaleOrderId) {
await this.orm.call("sale.order.line", "search_read", [[['order_id', '=', parseInt(selectedSaleOrderId)]]]).then(function (result) {
var $productDropdown = $('#products_id');
await this.orm.call("sale.order.line", "search_read", [
[['order_id', '=', parseInt(selectedSaleOrderId)]],
['product_id']
]).then(function (result) {
$productDropdown.empty();
$productDropdown.append($('<option>', {
value: '',
text: 'Select Product'
}));
$.each(result, function (i, saleOrderLine) {
$.each(result, function (i, saleOrderLine) {
$productDropdown.append($('<option>', {
value: saleOrderLine.product_id[0], // Assuming product_id is a many2one field
text: saleOrderLine.product_id[1], // Assuming product_id has a name field
}));
});
$productDropdown.append($('<option>', {
value: saleOrderLine.product_id[0],
text: saleOrderLine.product_id[1],
}));
});
});
} else {
$productDropdown.empty();
$productDropdown.append($('<option>', {
value: '',
text: 'Select Product'
}));
}
},
async _onSubmit(ev) {
ev.preventDefault();
// Get the selected sale order ID, customer ID, and product ID
var self = this;
// Get the selected values
var selectedSaleOrderId = $('#sale_order_id').val();
var selectedCustomerId = $('#customer_id').val();
var selectedProductId = $('#products_id').val();
var errorMessageElement = $('#error_message');
if (selectedSaleOrderId && selectedCustomerId && selectedProductId) {
await self.orm.call('warranty.claim', "search_count", [[['sale_order_id', '=', parseInt(selectedSaleOrderId)]]]).then(function (count) {
if (count > 0) {
errorMessageElement.text("A warranty claim for this sale order already exists.");
setTimeout(function () {
errorMessageElement.text("");
}, 10000);
} else {
// Clear previous error messages
errorMessageElement.text("");
// Validate all fields are selected
if (!selectedCustomerId) {
errorMessageElement.text("Please select a customer.");
setTimeout(function () {
errorMessageElement.text("");
}, 5000);
return;
}
if (!selectedSaleOrderId) {
errorMessageElement.text("Please select a sale order.");
setTimeout(function () {
errorMessageElement.text("");
}, 5000);
return;
}
if (!selectedProductId) {
errorMessageElement.text("Please select a product.");
setTimeout(function () {
errorMessageElement.text("");
}, 5000);
return;
}
try {
// Check if warranty claim already exists for this sale order
const count = await self.orm.call('warranty.claim', "search_count", [
[['sale_order_id', '=', parseInt(selectedSaleOrderId)]]
]);
if (count > 0) {
errorMessageElement.text("A warranty claim for this sale order already exists.");
setTimeout(function () {
errorMessageElement.text("");
self.orm.call('sale.order', 'read', [[parseInt(selectedSaleOrderId)], ['is_warranty_check']]).then(function (saleOrderData) {
if (saleOrderData && saleOrderData[0] && saleOrderData[0].is_warranty_check === true) {
self.orm.call('product.product', 'read', [[parseInt(selectedProductId)], ['is_warranty_available']], ).then(function (productData) {
if (productData && productData[0] && productData[0].is_warranty_available === true) {
self.orm.call('warranty.claim', 'create', [{
'sale_order_id': parseInt(selectedSaleOrderId),
'customer_id': parseInt(selectedCustomerId),
'product_id': parseInt(selectedProductId),
}], ).then(function (result) {
window.location.href = '/warranty/claim/submit';
});
}
});
} else {
errorMessageElement.text("Selected product does not have warranty available.");
setTimeout(function () {
errorMessageElement.text("");
}, 10000);
}
});
}
});
}, 10000);
return;
}
// Check if sale order has warranty
const saleOrderData = await self.orm.call('sale.order', 'read', [
[parseInt(selectedSaleOrderId)],
['is_warranty_check']
]);
if (!saleOrderData || !saleOrderData[0] || saleOrderData[0].is_warranty_check !== true) {
errorMessageElement.text("Selected sale order does not have warranty available.");
setTimeout(function () {
errorMessageElement.text("");
}, 10000);
return;
}
// Check if product has warranty
const productData = await self.orm.call('product.product', 'read', [
[parseInt(selectedProductId)],
['is_warranty_available']
]);
if (!productData || !productData[0] || productData[0].is_warranty_available !== true) {
errorMessageElement.text("Selected product does not have warranty available.");
setTimeout(function () {
errorMessageElement.text("");
}, 10000);
return;
}
// All validations passed, create the warranty claim
await self.orm.call('warranty.claim', 'create', [{
'sale_order_id': parseInt(selectedSaleOrderId),
'customer_id': parseInt(selectedCustomerId),
'product_id': parseInt(selectedProductId),
}]);
// Redirect to success page
window.location.href = '/warranty/claim/submit';
} catch (error) {
console.error('Error creating warranty claim:', error);
errorMessageElement.text("An error occurred while creating the warranty claim. Please try again.");
setTimeout(function () {
errorMessageElement.text("");
}, 10000);
}
}
});
export default publicWidget.registry.WarrantyClaim;

2
website_warranty_management/views/website_registration_templates.xml

@ -14,7 +14,7 @@
</div>
<div class="col-md-12 mt-5 mb-5 mb-md-0" t-ref="body">
<div class="form">
<form action="/warranty/claim/submit" id="form_submit">
<form t-attf-action="/warranty/claim/submit" method="post" id="form_submit">
<!-- Customer Selection -->
<div>
<div class="o_row">

Loading…
Cancel
Save