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,那么我只想在采购行中装载默认仓库,否则我想装载所有仓库。那么我该怎么做。
最佳答案
我们可以尝试以下方式。
在上下文中传递值。例如:
<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)
我已经写了答案。我没有尝试。
关于odoo-8 - 在更改其他字段的值时应用动态域-Odoo,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45117764/