I'd like to create different sequences for a model based on a Selection field.
Right now I have just one sequence like this:
@api.model
def create(self, vals):
if vals.get('name', 'New') == 'New':
vals['name'] = self.env['ir.sequence'].next_by_code('mrp.worksheet.contract') or '/'
return super(mrp_worksheet_contract, self).create(vals)
name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
_defaults = {
'name': lambda self, cr, uid, context: self.pool.get('ir.sequence').next_by_code(cr, uid, 'mrp.worksheet.contract') or '',
}
But what happens if I want to create more than one sequence based on a field like this:
type_prod = fields.Selection([
('budgeted','Budgeted'),
('nonbudgeted','Non Budgeted'),
('direct','Direct Order'),
], string='Type of Order', index=True,
track_visibility='onchange', copy=False,
help=" ")
I have the sequence declared on my xml:
<openerp>
<data noupdate="1">
<!-- Sequences for contracts -->
<record id="seq_type_contract_code" model="ir.sequence.type">
<field name="name">contract sequence</field>
<field name="code">mrp.worksheet.contract</field>
</record>
<record id="seq_contract_code" model="ir.sequence">
<field name="name">contract sequence</field>
<field name="code">mrp.worksheet.contract</field>
<field name="prefix">10G-</field>
<field name="padding">5</field>
<field name="company_id" eval="False"/>
</record>
</data>
</openerp>
I guess I would have more than one sequence in my xml, but I can't find any example on how to use more than one depend on a Selection field.
Any ideas?
EDIT
I have this model, which has a sequence name field, what I want, is, depending on which option You select on this field
type_prod = fields.Selection([
('budgeted','Budgeted'),
('nonbudgeted','Non Budgeted'),
('direct','Direct Order'),
], string='Type of Order', index=True,
track_visibility='onchange', copy=False,
help=" ")
To create the same record but with a different sequence, for example, if user selects budgeted then it's going to be BO000 and if nonbudgeted is selected then the same record is created but with different sequence, it'll be NBO000 and if direct then DO000
When you save the record just check the value of your field then select the value from your sequence
I think this will do the job hope you get the idea