How to made the domain based on another table?


I would like to domain records from another table, is it possible?


def ModelA:
	__name__ = 'test.modela'
	name = fields.Char('Name')
	lines = fields.One2Many('test.modela.line', 'modela', 'Model A')
def ModelALine:
	__name__ = 'test.modela.line'
	modela = fields.Many2One('test.modela', 'Model A')
	employee = fields.Many2One('company.employee', 'Approver')
def ModelC:
	__name__ = 'test.modelc'
	name = fields.Char('Name')
	modela = fields.Many2One('test.modela')
	employee = fields.Many2One('company.employee', 'Approver', domain=[])

For this kind of Model Setup, For “Model C”, I would like domain/filter the emloyees which only exist on model “ModelALine”, after user select fields of “modela”?

domain can only have one field (as operand) per clause.
You must create a function field that exposes the available employees on the ModelC so it can be evaluated as value of the domain clause.

def ModelC:
    "Model C Line"
	__name__ = 'test.modelc'
	name = fields.Char('Name')
	modela = fields.Many2One('test.modela', 'Model A')
	employee_ids = fields.Function(fields.Char('Employee Ids', depends=['modela']), 'get_employee_ids')
	employee = fields.Many2One('company.employee', 'Approver', domain=[('id', 'in', [Eval('employee_ids')])], depends=['employee_ids'])
	def get_employee_ids(self, name=None):
		_ids = []
		if self.modela:
		    for m in self.modela:
        if _ids:
		    return ','.join(_ids)
		return "-1"

I try to sub another fields for getting the Ids, however, it do not return any value during creating a new record.

Am I doing a wrong way?

You can not use Char as value for a domain against a Many2One. It must be a list of ids so a Many2Many.