【发布时间】:2017-10-26 06:31:18
【问题描述】:
我在基于 product.product 的销售订单中有一个 Many2one('product_weight') 字段。我尝试在销售订单行(产品)中返回该字段值。在 product.template 我添加了一个复选框('is_weight')。因此,在“product_weight”的销售订单中,只有重量产品可用。那么,如何在销售订单行(product_id)中返回“product_weight”值?
我的代码在这里:
class sale_order_pet(models.Model):
_inherit = "sale.order"
product_weight = fields.Many2one('product.product', string='Service products', domain="[('is_weight','=',True)]")
@api.onchange('product_id')
def _onchange_action_weight_add(self):
res = self.product_id
print"resss:::", res
if res:
line_values = {'product_id': self.product_weight.id,
}
sale_order_line = self.env['sale.order.line'].create(line_values)
提前致谢
【问题讨论】:
-
您想在销售订单行中显示产品重量吗?
-
是的,我想在 product_id(销售订单行)中显示 product_weight
-
@PAWANSHARMA 您不能在 onchange 中创建记录,如果您只想显示
check_box('is_weight')的产品,那么只需找到所有产品 ID 并返回类似的域。[('id', 'in', ids)]] -
你好@Heroic,我已经用域过滤了我的product_weight。但是,问题与 onchange 功能有关。如何在product_weight上应用onchange,选择Product_weight后自动填写销售订单行(product_id)?
-
@PAWANSHARMA 所以可以将其添加到订单中。
self.order_line = [(0,0,{'product_id': self.product_weight.id})]
标签: python-2.7 odoo-10