تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2763 أدوات العرض

Hi mates, I'm new to odoo and using odoo 13. I'm trying to calculate maximum delivery to be made to a customer. Made a custom field in res.partner where we can add a percentage and that percent of product can be sent in delivery. When I add the amount more than the max it perfectly raises the exception, but when I add the amount within the max and entered product quantity the percentage becomes  zero.
Here's my code:

@api.onchange('qty_done')
def max_quantity_done(self):
all_customers = self.env['res.partner'].search([])
for customer in all_customers:
max_qty = self.product_uom_qty + (self.product_uom_qty*(customer.allowable_delivery_qty/100))
if self.qty_done > max_qty:
raise UserError(_('For this customer the excess allowed quantity is ' + str(customer.allowable_delivery_qty) +'% and Max allowed Done quantity is ' + str(max_qty)))

I am unable to understand why this is happening
الصورة الرمزية
إهمال
أفضل إجابة

Hi,

Try this code to calculate max_qty based on the allowable_delivery_qty of the current customer.

@api.onchange('qty_done')

def max_quantity_done(self):

    customer = self.partner_id

    max_qty = self.product_uom_qty + (self.product_uom_qty * (customer.allowable_delivery_qty / 100))

    if self.qty_done > max_qty:

        raise UserError(_('For this customer, the excess allowed quantity is ' + str(customer.allowable_delivery_qty) + '% and the max allowed Done quantity is ' + str(max_qty)))


Hope it helps

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 22
4054
5
يوليو 21
29209
3
يونيو 21
12618
0
أبريل 20
3033
1
ديسمبر 21
5071