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

i have to print like as previous year and present year 

For Ex: if i given today date 

it should show like 2018-19

when i give the date as my selection

Avatar
Discard
Best Answer

First, create a sequence for your corresponding model.

eg:

1.


<record id="seq_id_id" model="ir.sequence">
<field name="name">name</field>
<field name="code">model.name</field>
<field name="prefix">- %(y) </field>
<field name="padding">3</field>
</record>

2.

override Create function:


from datetime import datetime, date

@api.model
def create(self, vals):
res = super(batch_payment, self).create(vals)
    next_year = date.today().year - 1
res.name = str(next_year) + self.env['ir.sequence'].next_by_code('model.name')
    # or use str(next_year)[2:] for geting last two digits. eg 2018 -> 18, use it for the sequence.
# do the changes needed. this is the logic
    return res




Avatar
Discard
Author

Thanks for your answer

Related Posts Replies Views Activity
2
Nov 24
262
1
Oct 24
328
4
Oct 24
323
2
Oct 24
360
2
Dec 24
661