Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
23808 Visualizzazioni

Hello All,

I want to change invoice sequence number like Inv/assessment year(AY)/Monthname/0001

For Example Inv/19-20/July/0001

I have follow below step to achive this things

Setting-->Technical-->Sequences&identifiers-->Sequence and search invoice.

Modified prefix as Inv/%(year)s/%(month)s/ and I got the new invoice number as Inv/2019/07/0001 but I want to invoice number as Inv/19-20/July/0001

Thanks in advance

Ankit H Gandhi

Avatar
Abbandona
Autore Risposta migliore

Hello All,

I found this solution using re-define method of _get_prefix_suffix

def _get_prefix_suffix(self):
def _interpolate(s, d):
return (s % d) if s else ''

def _interpolation_dict():
now = range_date = effective_date = datetime.now(pytz.timezone(self._context.get('tz') or 'UTC'))
if self._context.get('ir_sequence_date'):
effective_date = fields.Datetime.from_string(self._context.get('ir_sequence_date'))
if self._context.get('ir_sequence_date_range'):
range_date = fields.Datetime.from_string(self._context.get('ir_sequence_date_range'))

sequences = {
'year': '%Y', 'month': '%m', 'day': '%d', 'y': '%y', 'doy': '%j', 'woy': '%W',
'weekday': '%w', 'h24': '%H', 'h12': '%I', 'min': '%M', 'sec': '%S'
}
if range_date:
ay = str(range_date.year)[2:] + '-' + \
str(range_date.year + 1)[2:]
sequences.update({'ay': ay, 'month_text': '%B'})
res = {}
for key, format in sequences.items():
res[key] = effective_date.strftime(format)
res['range_' + key] = range_date.strftime(format)
res['current_' + key] = now.strftime(format)

return res

d = _interpolation_dict()
try:
interpolated_prefix = _interpolate(self.prefix, d)
interpolated_suffix = _interpolate(self.suffix, d)
except ValueError:
raise UserError(_('Invalid prefix or suffix for sequence \'%s\'') % (self.get('name')))
return interpolated_prefix, interpolated_suffix
Then Go to 
Setting-->Technical-->Sequences&identifiers-->Sequence and search invoice.

Change Prefix to: Inv/%(ay)s/%(month_text)s/

Appreciate to Mitul Shingala and OdooTools

Best Regards,

Ankit H Gandhi.


Avatar
Abbandona

I am using Odoo 13 and I would like to use this code to implement the fiscal year range into my invoice. Could you guide me how to locate the ir.sequence model and the adjusting the code to reflect the changes in the invoice.

Risposta migliore

Available suffixes' and prefixes' legends are available right on the sequence form:

  • Current Year with Century: %(year)s

  • Current Year without Century: %(y)s (in your case '19', centure alone is not available) 

  • Month: %(month)s (only number, textual representation is not available)

  • Day: %(day)s

  • Day of the Year: %(doy)s

  • Week of the Year: %(woy)s

  • Day of the Week (0:Monday): %(weekday)s

  • Hour 00->24: %(h24)s

  • Hour 00->12: %(h12)s

  • Minute: %(min)s

  • Second: %(sec)s

As you can see those standard legends can not help to achieve your goals.

You should add a bit of coding to re-define the method '_get_prefix_suffix' of the model ir.sequence (the module 'base') by adding extra legends expressions.


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
set 20
2575
0
set 18
3209
1
feb 17
3291
1
feb 24
1130
3
lug 23
5064