[IMP] ensan_website_sale: activate product details gifts

This commit is contained in:
Abdurrahman Saber 2025-04-17 07:53:13 +02:00
parent 4e33630002
commit e9f31e4134
4 changed files with 59 additions and 2 deletions

View File

@ -15,6 +15,30 @@ class SaleOrder_Inherit(models.Model):
for sale in self:
sale.sale_order_portal_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + sale.get_portal_url()
def check_mobile_number_validation(self, phone):
if phone[0] == '+' and phone[1] != '0':
if phone[1:4] == '966':
if len(phone[4:]) >= 8:
return phone
else:
phone = phone[0] + '966' + phone[1:]
elif phone[0] == '+' and phone[1] == '0':
phone = phone[0] + '966' + phone[2:]
elif phone[0] == '0' and phone[1] == '5':
phone = '+966' + phone[1:]
elif phone[0:2] == '00': # 00966555555555
if phone[2:5] == '966':
phone = '+' + '966' + phone[5:]
elif phone[0] == '0': # 0966555555555
if phone[1:4] == '966':
phone = '+' + '966' + phone[4:]
else:
if phone[0:3] == '966':
phone = '+' + phone
else:
phone = '+' + '966' + phone
return phone
def _cart_update(self, *args, **kwargs):
res = super(SaleOrder_Inherit, self)._cart_update(*args, **kwargs)
order_line = self.env['sale.order.line'].browse(res.get('line_id'))
@ -31,7 +55,7 @@ class SaleOrder_Inherit(models.Model):
'product_id': int(i.get('product_id')),
'donated_amount': float(i.get('donated_amount')),
'donator_name': i.get('donator_name'),
'donator_mobile_number': i.get('donator_mobile_number')
'donator_mobile_number': self.check_mobile_number_validation(i.get('donator_mobile_number')).replace('+', '')
}))
order_line.extra_donators_ids = extra_donators_ids
return res

View File

@ -17,6 +17,7 @@
<group>
<group>
<field name="is_quick_donation"/>
<field name="is_gift"/>
<field name="donation_type"/>
<field name="target_amount"/>
<field name="donated_amount"/>

View File

@ -5,6 +5,7 @@ from odoo.exceptions import ValidationError
from odoo.http import request
import logging
import phonenumbers
import json
from phonenumbers.phonenumberutil import NumberParseException
_logger = logging.getLogger(__name__)
@ -12,6 +13,29 @@ _logger = logging.getLogger(__name__)
class WebsiteSaleExtended(WebsiteSale):
@http.route()
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
res = super(WebsiteSaleExtended, self).cart_update(product_id, add_qty=add_qty, set_qty=set_qty, **kw)
sale_order = request.website.sale_get_order()
product_custom_attribute_values = None
if kw.get('product_custom_attribute_values'):
product_custom_attribute_values = json.loads(kw.pop('product_custom_attribute_values'))
no_variant_attribute_values = None
if kw.get('no_variant_attribute_values'):
no_variant_attribute_values = json.loads(kw.pop('no_variant_attribute_values'))
sale_order._cart_update(
product_id=int(product_id),
add_qty=add_qty,
set_qty=set_qty,
product_custom_attribute_values=product_custom_attribute_values,
no_variant_attribute_values=no_variant_attribute_values,
**kw
)
return res
@http.route()
def checkout(self, **post):
response = super(WebsiteSaleExtended, self).checkout(**post)

View File

@ -3,6 +3,14 @@ odoo.define("ensan_website_sale.product_details_gifts", function (require) {
var publicWidget = require("web.public.widget");
function ArabictoEnglishNumber(strNum) {
var ar = "٠١٢٣٤٥٦٧٨٩".split("");
var en = "0123456789".split("");
strNum = strNum.replace(/[٠١٢٣٤٥٦٧٨٩]/g, (x) => en[ar.indexOf(x)]);
strNum = strNum.replace(/[^\d]/g, "");
return strNum;
}
publicWidget.registry.WebsiteSale.include({
_submitForm() {
const $product = $("#product_detail");
@ -13,7 +21,7 @@ odoo.define("ensan_website_sale.product_details_gifts", function (require) {
gift_box_list.push({
product_id: product_id,
donator_name: $(this).find("input.input-gifteeName").val(),
donator_mobile_number: $(this).find("select.country-code").val() + $(this).find("input.input-gifteeNumber").val(),
donator_mobile_number: $(this).find("input.input-gifteeNumber").val(),
donated_amount: ArabictoEnglishNumber($(this).find("input.donation-input-amt").val()),
});
});