Reputation: 237
I want to calculate total product weight in odoo quotations and sale orders, but i don't know that how to write the method for it, can someone give me hint about it?
class ProductWeight(models.Model):
_inherit = "sale.order"
th_weight = fields.Float('Weight')
@api.one
def _calcweight(self):
currentweight = 0
for weight in self.weight_ids:
currentweight = currentweight + weight.th_weight
self.weight_total = currentweight
weight_total = fields.Float('Total Weight', store=True, compute="_calcweight")
here is my method for calculating total weight above, but its not right, give me 404 errors.
Upvotes: 0
Views: 685
Reputation: 36
Well I suggest using the following code
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')
you must set the parameter weight in the product master data in any case you can modify the th_weight field so that it is not related to the product, a user would have to fill this information
Upvotes: 2