Skip to Content
Menu
This question has been flagged
1 Reply
3073 Views

Hello,

Maybe some one can help me or put me in the right direction.

we are using the coupon program of Odoo 13 for E-commerce. it works perfect but Odoo generate coupon codes of 17 till 19 numbers.  10865989607408703818

Is there a way we can change this to 6 numbers?

Thank you for all the help in advance.

Avatar
Discard
Best Answer

Hi Wilfried Sip,

Please update the code of "sale_coupon > models > sale_coupon.py" as follows.


import random

from odoo import api, fields, models


class SaleCoupon(models.Model):

_inherit = 'sale.coupon'


@api.model

def _generate_code(self):

#overwrite function

# set size of coupon code

n = 6

min_no = pow(10, n - 1)

max_no = pow(10, n) - 1

return random.randint(min_no, max_no)


code = fields.Char(default=_generate_code)


Hope this reference is helpful to you.

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Discard