【发布时间】:2019-01-10 12:23:44
【问题描述】:
我对 Odoo 很陌生,经常被卡住。现在,我真的陷入了没有解决方案的困境。 我的目标是计算消耗的原材料。 问题是我想用mrp.bom.line 中的product_id 初始化一个模型(这里是assessment.raw.material)。我尝试使用“default=”、“.create()”,但它不起作用。 我认为如果我得到所有原材料的所有 product_id,我可以很容易地用 sql 查询填充所有列。 你能帮助我吗? 还是我弄错了? 或者你有更好的主意吗?谢谢你。对不起我的英语不好。
class AssessmentRawMaterials(models.Model):
_name = 'assessment.raw.materials'
# get the product_id from mrp.bom.line
# which is nomenclature of each
# finished product
product_id = fields.Many2one(
string='Matières premières',
comodel_name='mrp.bom.line',
ondelete="no action",
store=True
)
# get the product unit of measure
# by calling the variable name of
# product_id
product_uom_name = fields.Char(
string=u'Unité de mesure',
related='product_id.product_id.name'
)
# compute using sql query,
# long long
# inner join
# from sale.order to mrp.bom.line
raw_material_qty = fields.Integer(
string=u'Quantité de matières premières',
default=0
)
【问题讨论】:
-
你能分享更多关于模型关系的信息吗?首先要注意:您有一个字段
product_id,它不是产品而是bom 行。感觉就是不对。你如何创建模型assesment.raw.materials的记录? -
两个模型(assessment.raw.material和mrp.bom.line)之间只有一个关系(many2one),我只想复制列product_id mrp.bom.line 到assessment.raw.materials 的product_id。 assessment.raw.materials 中的记录创建不是用户输入,而是必须自动和自动更新。
-
如果可能,请编辑您的问题。您可以使用相关字段,我会写一个简短的答案。