Skip to Content
Menu
This question has been flagged
4 Replies
4684 Views

Once the login page is kept inactive for a while or page is re-logged in, the sequence numbers starts from begining and I am unable to figure out where exaclty the thing is going wrong.

Like in sale.order the name field is not repeated again. If SO0001 is existing, it will not be repeated again, but in my case SR0001 is getting created again.

Field :

name = fields.Char(string='Name', required=True, copy=True, readonly=True, states={'draft': [('readonly', False)]}, index=True, default=lambda self: _('New'))

Py file : 

@api.model

    def create(self, vals):

        if vals.get('name', _('New')) == _('New'):

            vals['name'] = self.env['ir.sequence'].next_by_code('sample.kit') or _('New')

        

        if 'user_id' in vals:

            if not self.env['hr.employee'].browse(vals['user_id']).user_id:

                raise UserError(_('In order to create a Sample Kit Request for this employee, you must link him/her to a user.'))

        res = super(SampleKitManagement, self).create(vals)

        res.write({'state': 'draft'})

        return res


XML File :

<record id="ir_seq_sample_request_number" model="ir.sequence">

<field name="name">Sample Request</field>

<field name="code">sample.kit</field>

<field name="prefix">SR</field>

<field name="padding">4</field>

<field name="number_increment">1</field>

<field name="number_next_actual">1</field>

<field name="implementation">standard</field>

</record>

Regards.

Sumit Sinha

Avatar
Discard

Can you make sure "number_next_actual" value changes on each creation.

(Except for these twoo cases page is kept inactive for a while or page is re-logged in)

Author Best Answer

My sequence xml data was missing the noupdate=True and that was the actual reason.

Now, the sequence numbers are not getting repeated.

Thanks for answers.


Avatar
Discard
Best Answer

use copy=False in field as shown


name = fields.Char(string='Name', required=True, copy=False, readonly=True, states={'draft': [('readonly', False)]}, index=True, default=lambda self: _('New'))

Avatar
Discard
Best Answer

Write a constraints on name field like sale order and make sure you sequence xml have noupdate=True

Avatar
Discard