Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4395 มุมมอง

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?

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ย. 22
2326
0
ก.ย. 20
3004
4
พ.ค. 18
11280
0
เม.ย. 16
3304
One2many onchange in ODOO แก้ไขแล้ว
3
มี.ค. 16
14170