Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
5318 Zobrazení

I have three models:

class Team(models.Model):
    _name = 'myModule.team'
    _description = 'Team'
    name = fields.Char('Name')
   employee_link_ids = fields.One2many('myModule.link', 'team_id', 'Team Members')

class Employee(models.Model):
    _name = 'new_module.employee'
    _description = 'Employee'
    name = fields.Char('Name')

class Link(models.Model):
    _name = 'myModule.link'
    _description = 'Links Employee to Team and allows the user to assign a role to the employee.'
    role = fields.Char('Role')
    employee_id = fields.Many2one('myModule.employee', 'Employee')
    team_id = fields.Many2one('myModule.team', 'employee_line_ids')

With the corresponding view:

<record id="view_myModule_form" model="ir.ui.view">

<field name="name">myModule.form</field>

<field name="model">myModule.team</field>

<field name="arch" type="xml">

<form>

<sheet>

<label for="name" class="oe_edit_only"/>

<h1>

<field name="name"/>

</h1>

<group>

<field name="employee_link_ids">

<tree editable="bottom">

<field name="employee_id"/>

<field name="role"/>

</tree>

</field>

</group>

</sheet>

</form>

</field>

</record>

 

When I add a Link record to the One2many with a particular Employee, I don't want that employee to show up in the employee_id drop downs for any existing or future child Link records for this Team.

The Employee should still be available for all other Teams where they haven't been used.

The feature should be workable before the record is saved.

I've tried a lot things including passing a list of values containing the IDs of the employee_id fields for each Link in the One2many to all the child Links, and also trying to put the list of values into context to be. Nothing has worked so far.

Does anyone have any ideas how this could be approached?

Thanks!

Avatar
Zrušit
Nejlepší odpověď

You try: fields_view_get . You can search in your odoo:

Example:

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AccountInvoiceLine, self).fields_view_get( view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if self._context.get('type'):
doc = etree.XML(res['arch'])
for node in doc.xpath("//field[@name='product_id']"):
if self._context['type'] in ('in_invoice', 'in_refund'):
 node.set('domain', "[('purchase_ok', '=', True)]")
else:
node.set('domain', "[('sale_ok', '=', True)]")
res['arch'] = etree.tostring(doc)
return res
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
říj 22
3300
1
srp 19
2333
1
bře 23
2249
0
pro 22
2887
1
říj 22
3792