Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5400 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 22
3365
1
thg 8 19
2459
1
thg 3 23
2375
0
thg 12 22
2996
1
thg 10 22
3859