首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置many2one字段的默认值?

如何设置many2one字段的默认值?
EN

Stack Overflow用户
提问于 2016-11-09 18:55:18
回答 2查看 860关注 0票数 0

我是Odoo9社区的新手。我在我的自定义模块中创建了继承sale.order.line的many2one字段,我想为many2one字段设置默认值,条件为fto call the funscion is the product bill of material。实现这一目标的步骤是什么?感谢您的时间。

EN

回答 2

Stack Overflow用户

发布于 2016-11-10 14:48:40

以本例为例,我将在sale.order中选择products属于一个仓库,并将其返回给sale.order.line中的product_id

代码语言:javascript
复制
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)]}}
票数 0
EN

Stack Overflow用户

发布于 2016-11-10 20:52:29

Unit_rate类(models.Model):

代码语言:javascript
复制
_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):

代码语言:javascript
复制
_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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40505249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档