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

this is my code
py file:
     @api.model
        def create(self, vals):
            if vals.get('name', 'New') == 'New':
                vals['sequence_id']=self.env['ir.sequence'].next_by_code('seq.attendance') or '/'
            return super(attendance, self).create(vals)
xml file:
     <?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data noupdate="1">
        <record id="seq_atttendance" model="ir.sequence">
            <field name="name">General Files proceedings Sequence</field>
            <field name="code">seq.attendance</field>
            <field name="prefix">File/%(year)s/%(month)s/%(day)s/</field>
            <field name="padding">5</field>
            <field eval="1" name="number_increment"/> 
        </record>
    </data>
 
</odoo>

where is the problem could you please give me the solution


Avatar
Discard

Use meaningful titles for the questions

Best Answer

Hi,

If you are looking to create a sequence for your model, please see the below code for the sale order sequence.

In XML, define the sequence,

<record id="seq_sale_order" model="ir.sequence">
<field name="name">Sales Order</field>
<field name="code">sale.order</field>
<field name="prefix">SO</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>


Then In the Python define a field to which the sequence has to be given,

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


Then override the create method and assign the sequence,

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('sale.order') or _('New')
result = super(SaleOrder, self).create(vals)
return result


Thanks

Avatar
Discard
Best Answer

Hello,

 Have you given proper inheritance for attendance model?

Have you added .py in __init__.py and xml file in __manifest__.py?

Logged in user having permission to read ir.sequence?

Avatar
Discard
Best Answer
hey your are missed the below line in xml
<field name="use_date_range">True</field>
 
Try this
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="seq_atttendance" model="ir.sequence">
<field name="name">General Files proceedings Sequence</field>
<field name="code">seq.attendance</field>
<field name="prefix">File/%(year)s/%(month)s/%(day)s/</field>
<field name="padding">5</field>
<field name="use_date_range">True</field>
<field eval="1" name="number_increment"/>
</record>
</data>

</odoo>
Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
18020
1
Sep 23
1203
3
May 23
4092
7
Apr 23
47093
1
Dec 22
6435