I am new in odoo 9 comunity.I have created many2one filed in my custom module that inherit sale.order.line and I would like to set default value for that many2one field with the condition fto call the funscion is the product that come with bill of material. what are steps to get that purpose? thank for your times.
2 Answers
0
votes
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')
class 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')
0
votes
Take this example, here i am taking products belongs a warehouse selected in sale.order
and return this to product_id
in 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)]}}