我是odoo 9社区的新手。我已经在我的自定义模块中创建了很多2个文件继承了sale.order.line,我想为那个many2one字段设置默认值,条件是fto调用funscion是产品那个随附物料清单。达到这个目的的步骤是什么?谢谢你的时间。
答案 0 :(得分:0)
举个例子,我在这里将产品属于sale.order
中选择的仓库,并将其返回product_id
中的sale.order.line
。
obj_location = self.pool.get('stock.warehouse').browse(cr, uid, warehouse_id, context=context).lot_stock_id.id
obj_inventory = self.pool.get('stock.quant').search(cr, uid, [('location_id', '=', obj_location)])
product_ids = []
products_qty = []
for obj in obj_inventory:
obj_products_id = self.pool.get('stock.quant').browse(cr, uid, obj)
product_ids.append(obj_products_id.product_id.id)
return {'domain': {'product_id': [('id', 'in', product_ids)]}}
答案 1 :(得分:0)
class unit_rate(models.Model):
_name = "sale.order.line.width"
name = fields.Char(u'Tên', required=True)
rate = fields.Float(u'Hệ số', required=True, default=1)
unit_id = fields.Many2one('product.uom', string=u'Đơn vị', required=True)
description = fields.Text(u'Chú thích')
类SaleLine(models.Model):
_inherit = "sale.order.line"
@api.model
def create(self, vals):
if vals['rate'] < 1:
raise UserError(_(u'Không thể đưa vào hệ số nhỏ hơn 0'))
return super(unit_rate, self).create(vals)
_inherit = "sale.order.line"
width_id = fields.Many2one('sale.order.line.width', u'Kiểu tính')