Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
23620 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar

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.

Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
sept 20
2424
0
sept 18
3064
1
feb 17
3113
1
feb 24
1016
3
jul 23
4883