Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
7202 Widoki

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? 


Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.




Awatar
Odrzuć

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

Najlepsza odpowiedź

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')



Awatar
Odrzuć
Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
1
gru 19
5266
4
sty 22
7230
0
sty 21
2358
5
lip 19
4831
1
maj 16
3811