콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5575 화면

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!

아바타
취소
베스트 답변

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
아바타
취소
관련 게시물 답글 화면 활동
1
10월 22
3572
1
8월 19
2602
1
3월 23
2538
0
12월 22
3176
1
10월 22
4062