Skip to Content
Menu
This question has been flagged
2 Replies
3113 Views

Hi, i have created a sequence with following definition in .py file :

reference = fields.Char(string='Order Reference', required=True, copy=False, readonly=True,
default=lambda self: _('New'))

and in create method:

@api.model
def create(self, vals):
if vals.get('reference', _('New')) == _('New'):
vals['reference'] = self.env['ir.sequence'].next_by_code('hospital.patient') or _('New')
res = super(HospitalPatient, self).create(vals)
return res

i couldn't understand what i'm missing(using odoo14). would you help please ?

Thanks



Avatar
Discard
Author Best Answer


Thanks Jainesh ,


i have found the error. it's data file where sequence is initiated. i have misspelled the tag which indicate to model name.


Avatar
Discard
Best Answer

Hello Abdalla,

You should make a changes in vals['reference'] = self.env['ir.sequence'].next_by_code('hospital.patient') or _('New')

You should change in ('hospital.patient') replace it with code from ir.sequence

ex :-

then you should apply like this in python side
vals['reference'] = self.env['ir.sequence'].next_by_code('sale.order.test') or _('New')

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari 

Avatar
Discard

Here is the example :-

ex :-
<record id="seq_sale_order_test" model="ir.sequence">
<field name="name">Sales Order Test</field>
<field name="code">sale.order.test</field>
<field name="prefix">ST</field>
<field name="padding">4</field>
<field name="company_id" eval="False"/>
</record>