Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4381 Weergaven

Hello,

I'm trying to calculate the cost of shipping an item in a box that can have several items. The box has a fixed shipping cost and the cost per item is calculated by dividing the shipping cost by the number of items.

I expect the cost field of the line to be updated when a new line is added before saving the form. However the value is not updated and the onchange call returns an empty value (in fiddler).

{"jsonrpc": "2.0", "id": 844836927, "result": {"value": {}}}


class Shipping(models.Model):    
    _name = 'shipping.shipping'
    shipping_cost = fields.Float(string='Shipping cost')
    shipping_line_ids = fields.One2many('shipping.line', 'shipping_id', string='Shipping items')

    @api.onchange('shipping_line_ids')
    def onchange_shipping_line_ids(self):
        number_of_items = len(self.shipping_line_ids)
     if number_of_items == 0:
            return
        line_cost = self.shipping_cost / number_of_items
        for line in self.shipping_line_ids:
            line.cost = line_cost

class ShippingLine(models.Model):
    _name = 'shipping.line'
    shipping_id = fields.Many2one('shipping.shipping', string='Shipping')
    cost = fields.Float(string='Cost')


What I am doing wrong?

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
sep. 22
2306
0
sep. 20
2988
4
mei 18
11236
0
apr. 16
3291
3
mrt. 16
14129