Python 如何计算odoo中的产品重量?
我想计算奥多报价单和销售订单中的产品总重量,但我不知道如何编写方法,有人能给我一些提示吗Python 如何计算odoo中的产品重量?,python,openerp,odoo-8,Python,Openerp,Odoo 8,我想计算奥多报价单和销售订单中的产品总重量,但我不知道如何编写方法,有人能给我一些提示吗 这是我计算上述总重量的方法,但它不正确,请给我404个错误。我建议使用以下代码 from openerp import models, fields, api class ProductWeight(models.Model): _inherit = 'sale.order.line' th_weight = fields.Float(string='Weight',
这是我计算上述总重量的方法,但它不正确,请给我404个错误。我建议使用以下代码
from openerp import models, fields, api
class ProductWeight(models.Model):
_inherit = 'sale.order.line'
th_weight = fields.Float(string='Weight',
store=True,
related='product_id.weight')
class ProductWeightOrder(models.Model):
_inherit = 'sale.order'
@api.depends('order_line.th_weight')
def _calcweight(self):
currentweight = 0
for order_line in self.order_line:
currentweight = currentweight + order_line.th_weight
self.weight_total = currentweight
weight_total = fields.Float(compute='_calcweight', string='Total Weight')
您必须在产品主数据中设置参数权重。在任何情况下,您都可以修改THU权重字段,使其与产品无关,用户必须填写此信息。我建议使用以下代码
from openerp import models, fields, api
class ProductWeight(models.Model):
_inherit = 'sale.order.line'
th_weight = fields.Float(string='Weight',
store=True,
related='product_id.weight')
class ProductWeightOrder(models.Model):
_inherit = 'sale.order'
@api.depends('order_line.th_weight')
def _calcweight(self):
currentweight = 0
for order_line in self.order_line:
currentweight = currentweight + order_line.th_weight
self.weight_total = currentweight
weight_total = fields.Float(compute='_calcweight', string='Total Weight')
您必须在产品主数据中设置参数权重。在任何情况下,您都可以修改THU weight字段,使其与产品无关,用户必须填写此信息它给我404未找到的错误。您可以分享问题的答案吗?404的意思非常具体,所以你似乎在不正确地使用API这是我的完整代码,我想我在某个点上犯了错误,我不明白,让我编辑问题我已经做了,现在为我工作它给我404未发现错误你能分享一个问题吗?404的意思非常具体,所以你似乎在错误地使用API这是我的全部代码,我想我在某个点上犯了错误,我不明白,让我编辑一下问题我已经做了,现在为我工作