Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
7277 Vizualizări

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? 


Imagine profil
Abandonează
Autor Cel mai bun răspuns

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.




Imagine profil
Abandonează

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

Cel mai bun răspuns

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



Imagine profil
Abandonează
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

Related Posts Răspunsuri Vizualizări Activitate
1
dec. 19
5352
4
ian. 22
7330
0
ian. 21
2473
5
iul. 19
4967
1
mai 16
3906