This question has been flagged
4 Replies
6062 Views

Hi,

I tried to mimic hr_recruitment module by allowing customisable of stages instead of a static one.

So instead of doing the below

state = fields.Selection([
('draft', "Draft"),
('confirmed', "Confirmed"),
('done', "Done"),
])

I'm create a Stage class

class Stage(models.Model):
_name = "warranty.stage"
_description = "Stage of Warranty Tracking"
_order = 'sequence'
name = fields.Char('Name', required=True)
sequence = fields.Integer('Sequence', help="Gives the sequence order when displaying a list of stages.")
description = fields.Text('Description')
fold = fields.Boolean('Folded in Kanban View',
help='This stage is folded in the kanban view when'
'there are no records in that stage to display.')
registration_ids = fields.One2many(
'warranty.registration', 'stage_id', string="Registrations")
_defaults = {
'sequence': 1,
'fold': False,
}

and then in another class Registration, it wiill have the stage_id attribute.

stage_id = fields.Many2one('warranty.stage', ondelete='set null', string="Stage")


The Registration view form will have the 

<form string="Registration Form">
<header>
<field name="stage_id" widget="statusbar" clickable="True"/>
</header>

However, I have 3 Stages configure, namely New, Registered, Rejected.

However, if my Registration object that is under New, for example will not highlight in the form view.

What am I missing here? 


Avatar
Discard
Author Best Answer

There is no need  to use selection field.


Due to the fact that I create 2 field of the same, stage_id with widget="status bar", and stage_id normal.

The Form failed to highlight the status bar. Removing the duplicate field solves my problem.

Therefore using using the fields.Many2one, will also work for statusbar.




Avatar
Discard

Thanks for your reply

can you tell me how to delete the old field i.e stage_id?

I used xpath with replace empty and it didnt work

Thanks

Best Answer

Your stage_id field still need to be a selection but pass a function name as a reference or string name of the function that collect the values of your Stage class records instead of a simple list of tuples. Something like this:

 
    @api.model def _get_stages(self):
        stage_ids = self.env['warranty.stage'].search([]) return [(stage.name,stage.name) for stage in stage_ids]

    stage_id = fields.Selection('_get_stages',string='Stage')



Avatar
Discard
Author

Thanks Axel. I tried your code,but it doesn't work on v8. Also I need the stage_id as multi-relationship with other classes. However, I did find my problem, I'll post my answer next.

Sorry, I'm using a lot of Odoo alfa v9 this days but the idea is the same, search for the values you wana use in the selection from whatever source you may have and declare a function field with that