This question has been flagged
2 Replies
3582 Views

Hi, 

how can i assign a number id to every maintenance request created?


Im using the Equipment module on Odoo 10.


Thks

Avatar
Discard
Best Answer

Hi,

If you are looking to create a sequence for the model maintenance request , like in the sales, like SO001,SO002 etc,


In the XML file create a sequence like this,

<record id="seq_material_request" model="ir.sequence">
<field name="name">Material Request</field>
<field name="code">material.request</field>
<field name="prefix">MR</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>

Then,

You have to define a field in python in this model and you have to write the value to it, for that

name = fields.Char(string='Request  No', required=True, copy=False, readonly=True,
index=True, default=lambda self: _('New'))

@api.model
def create(self, vals):
"""Overriding the create method and assigning the the sequence for the record"""
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('material.request') or _('New')
res = super(ClassName, self).create(vals)
return res


Thanks

Avatar
Discard
Author

Perfect Niyas,

With that i added the sequence.

in a view, how can call the current id applied to a maintenance request. Im using the print maintenance request module.

Thnks

If you follow the above method you will get the sequence in the field named name

Author

Im using a module to print the maintenance request, is a qweb report using the fields of the doc itself. I can call the equipment id, priority, and so on just adding the field name to the variable doc. (doc.equipment _id).

"<span t-field="doc.equipment_id.name"/>"

is this qweb report, how can call the sequence number of the current document?

thnks

Author Best Answer

Hi Niyas,

My knowledge of programming is very basic, do i need to make those two files adapted to work with the maintenance model and install it from the web like any other module?


Thks

Avatar
Discard

See updated answer