class procurement(models.Model)
_name="procurement"
procurement_line_ids = fields.One2many(comodel_name='procurement.line', inverse_name='procurement_id', string='Procurement Lines')
global_procurement = fields.Boolean("Global Procurement",default=True)
class procurement_line(models.Model)
_name="procurement.line"
procurement_id = fields.Many2one(comodel_name='procurement', string='Procurement')
warehouse_id = fields.Many2one(comodel_name='stock.warehouse', string='Warehouse')
class stock_warehouse(models.Model)
_name="stock.warehouse"
is_default_warehouse = fields.Boolean(string="Is Default Warehouse?",default=False)
如果global_procurement为True,那么我只想在采购线中加载默认仓库,否则我想加载所有仓库。那我怎么能这样做呢。
答案 0 :(得分:3)
我们可以尝试以下方式。
在上下文中传递值。例如:
<field name="warehouse_id"
context="{'global_procurement': parent.global_procurement}"/>
检查 stock.warehouse 对象的上下文值 name_search()。例如:
@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
if self._context and self._context.get('global_procurement'):
default_list = [1,2,3] # set your logic to search list of default warehouse
return self.browse(default_list).name_get()
return super(Warehouse, self).name_search(name=name, args=new_args, operator=operator, limit=limit)
我在空中写了答案。我没有尝试过。
答案 1 :(得分:0)
我通过在字段中定义域来完成它(想法取自@ Odedra的回答)。
<field name="warehouse_id" required="1" domain="[('field_name','=',parent.global_procurement)]" options="{'no_create': True, 'no_quick_create':True, 'no_create_edit':True}" />