This question has been flagged
1 Reply
106 Views

We're in Odoo Online V16.


Currently, Odoo creates coupon codes like "044c-77dd-55b".

We need something more user-friendly and meaningful, like ... um ... let's say "OCTOBER2023".


I'm sure there's *got* to be some way somewhere to customize our coupon codes.


As it stands right now, we currently only need one single code for our pre-opening promotion (available to all visitors), but I'm 100% certain that it's something we'd like to do from here on out, and I'm sure we can't be the only ones to want this.


While I have found old posts on the topic for other versions of Odoo, I'm yet to find anything that pertains to V16, so any and all help would be GREATLY appreciated.
Our pre-launch sale is just a few days away, and we are nearing panic with simple snags like this.


Avatar
Discard
Best Answer

Hi,

You need to override the _generate_code method: odoo/coupon.py at 14.0 · odoo/odoo · GitHub

to generate a code like "OCTOBER2023".Below is an example of how you can achieve this customization:


def _generate_code(self):

        """Generate a code like OCTOBER2023."""

        # Get the current month and year

        month_name = calendar.month_name[self._context.get('date', fields.Date.today()).month]

        year = str(fields.Date.today().year)


        # Concatenate the month name and year to form the code

        return month_name.upper() + year


Hope it helps

Avatar
Discard