Python Odoo-Can';t model.py中的两个字段之和
为什么我不能在模型文件中对两个字段求和。下面的代码不起作用 正如您在上一节中看到的,我试图使用Python Odoo-Can';t model.py中的两个字段之和,python,odoo,Python,Odoo,为什么我不能在模型文件中对两个字段求和。下面的代码不起作用 正如您在上一节中看到的,我试图使用onchange,但没有成功 例如: 我需要字段“盘后金额”=“总价”/“产品数量” 如果您使用的是10个以下的odoo版本,请在xml字段中提及变量“总价”、“产品数量”和“使用on-change功能后的金额声明” 如果您使用的是9以上的odoo版本,请使用@api.onchange()decorator 请尝试在“sr.sale.price.history”模型中编写“onchange\u字段”函数
onchange
,但没有成功
例如:
我需要字段“盘后金额”=“总价”/“产品数量”
如果您使用的是10个以下的odoo版本,请在xml字段中提及变量“总价”、“产品数量”和“使用on-change功能后的金额声明” 如果您使用的是9以上的odoo版本,请使用@api.onchange()decorator 请尝试在“sr.sale.price.history”模型中编写“onchange\u字段”函数。 并尝试在创建后调用此函数,如下所示
sale_order_line_ids = self.env['sale.order.line'].sudo().search(domain,limit=sale_order_line_record_limit,order ='create_date desc')
for line in sale_order_line_ids:
sale_price_history_id = sale_history_obj.create({
'name':line.id,
'partner_id' : line.order_partner_id.id,
'user_id' : line.salesman_id.id,
'product_tmpl_id' : line.product_id.product_tmpl_id.id,
'variant_id' : line.product_id.id,
'sale_order_id' : line.order_id.id,
'sale_order_date' : line.order_id.date_order,
'product_uom_qty' : line.product_uom_qty,
'unit_price' : line.price_unit,
'currency_id' : line.currency_id.id,
'total_price' : line.price_subtotal
})
sale_price_history_id.onchange_field()
请指定Odoo版本好吗?我使用的是Odoo社区V12。您的销售历史ID在使用之前没有声明。@jo541它在另一个文件中声明为我上面的编辑,请检查它是否正确。但是您在哪里声明了变量(在方法onchange的独家新闻中)?你有什么错误吗?请写onchange函数在sr.sale.price.history模型中,因为字段在此模型中存在。检查我编辑的答案我这样做了,但我得到错误“ld
sale\u price\u history\u id
不存在”使用sale\u price\u history\u id。我看不到idsi使用了您编写的内容,但我仍然得到错误“ld sale\u price\u history\u id不存在”
class srSalePriceHistory(models.Model):
_name = 'sr.sale.price.history'
_description = 'Sale Price History'
name = fields.Many2one("sale.order.line",string="Sale Order Line")
partner_id = fields.Many2one("res.partner",string="Customer")
user_id = fields.Many2one("res.users",string="Sales Person")
product_tmpl_id = fields.Many2one("product.template",string="Template Id")
variant_id = fields.Many2one("product.product",string="Product")
sale_order_id = fields.Many2one("sale.order",string="Sale Order")
sale_order_date = fields.Datetime(string="Order Date")
product_uom_qty = fields.Float(string="Quantity")
unit_price = fields.Float(string="Price")
currency_id = fields.Many2one("res.currency",string="Currency Id")
total_price = fields.Monetary(string="Total")
amount_after_disc = fields.Float(string="After Disc")
sale_order_line_ids = self.env['sale.order.line'].sudo().search(domain,limit=sale_order_line_record_limit,order ='create_date desc')
for line in sale_order_line_ids:
sale_price_history_id = sale_history_obj.create({
'name':line.id,
'partner_id' : line.order_partner_id.id,
'user_id' : line.salesman_id.id,
'product_tmpl_id' : line.product_id.product_tmpl_id.id,
'variant_id' : line.product_id.id,
'sale_order_id' : line.order_id.id,
'sale_order_date' : line.order_id.date_order,
'product_uom_qty' : line.product_uom_qty,
'unit_price' : line.price_unit,
'currency_id' : line.currency_id.id,
'total_price' : line.price_subtotal
})
sale_price_history_id.onchange_field()