Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
3 Respostas
4117 Visualizações

Hello everyone. This is my first post here.

My client wants a custom name for their invoices in Odoo 16. I know that Odoo has this new, weird auto-incrementation feature, but this causes even more trouble for me because the client wants the name of the invoice to follow a pattern like this: journal prefix/increment number/month/year I/0001/03/23

When I make a custom name in Python and let Odoo increment it, it just increments 23 to 24, which is the year, and I need to increment 0001 to 0002.

My question is: should I work in the Odoo way and use the built-in name generator, inheriting some invoice and mixins features to match my requirements, or should I do it my Python way by generating the name using just the pattern and writing it to the invoice, which involves turning off Odoo's invoice naming feature? I will probably need to disable this feature since Odoo doesn't like it when the invoice name is changed in a way that was not previously described in this new weird feature.

I want to hear your opinions about interfering in Odoo with code in such a way.

Thanks for your answers


Avatar
Cancelar
Autor

The answer:
If you want to change the way odoo names invoices, all you need to do is override one of this 3 Regexes:
_sequence_monthly_regex = r'^(?P<prefix1>.*?)(?P<year>((?<=\D)|(?<=^))((19|20|21)\d{2}|(\d{2}(?=\D))))(?P<prefix2>\D*?)(?P<month>(0[1-9]|1[0-2]))(?P<prefix3>\D+?)(?P<seq>\d*)(?P<suffix>\D*?)$'
_sequence_yearly_regex = r'^(?P<prefix1>.*?)(?P<year>((?<=\D)|(?<=^))((19|20|21)?\d{2}))(?P<prefix2>\D+?)(?P<seq>\d*)(?P<suffix>\D*?)$'
_sequence_fixed_regex = r'^(?P<prefix1>.*?)(?P<seq>\d{0,9})(?P<suffix>\D*?)$'

this 3 variables tells odoo how to name Invoices, where is the index, month, year, day.
when you change one of these patterns only what you need to do is create one invoice by hand (you need to write the name of invoice matching pattern). Then odoo will use that name to create next invoices.
The path to module containing regex "addons/account/models/sequence_mixin.py"
Of course I recommend to not change this in original code, but to inherit this module and then override regex.
IMPORTANT is to make these regexes different from each other, otherwise Odoo won't know when to start new index from 1. If you changed month regex and created first invoice matching this pattern, then it will know to restart the count every month. If you changed yearly regex then it will restart sequence every year. The fixed regex probably counts invoices all the time and does not restart sequence (you must restart it manually).
For understand the prefix string i recommend to use chatGPT. It is good for task like this.

Autor Melhor resposta

Thank you very much for your suggestions, but it will not work for me.
Im working to set those names automatically without changing any month or year values by hand.
I am also working on making the sequence reset to 1 with each month.
The client requires that every month should start from 1 and he wants this prefix which Odoo doesn't like (INV/0001/month/year) 
I was thinking about something similar to linked list where each invoice would store internal index, and next index would be set based on highest index value from all invoices from given month.
My only problem is that odoo blocks me anytime I want to change name not its way.

Avatar
Cancelar
Melhor resposta

Hello, 

We came across this kind of scenario and worked for it, 

You can check this link if it helps to you :- https://apps.odoo.com/apps/modules/15.0/account_sequence_per_fiscalyear_cr/


Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
1
mar. 24
1475
3
nov. 24
4344
1
jul. 23
2573
0
jul. 23
25
2
jul. 23
3703