0
votes

I am struggling now with how to update my fields because it is related to another field. In the time that I change the value of my related fields and save it, it goes back to its original value. Why? Can I update related fields? anyone help. I am new in odoo, many thanks.

here's what I do.

ret_condition_id = fields.Many2one('asset.state', string="Condition", 
    related='ret_asset_id.asset_condition', store=True)

If I change my ret_condition_id into a new value, after I save it. It goes back to its original value.

2
What is the original value is it False is you Many2one field have a value because related field save the changes but only of the Many2one field is set a value. but you cannot create a new record from related field. only with delegate = True.Charif DZ
I updated my post. Thanks. Anyways, what delegate exact means?law rence
What is the value of ret_asset_idCharif DZ
ret_asset_id .asset_condition = 'new' and i want to change it to 'used'law rence
Check this link stackoverflow.com/questions/28834086/…, if store=True did not work.Kenly

2 Answers

0
votes

Related field always based its value in a relationship, If you change the relation its value will recalculate, if you change the value of related field manually it will recalculate when you save the changes.

You should use another field for your purpose.

0
votes

This is my solution on my question for the sake of others. I have a button receive and everytime the state in on received the data will update.

return_ids = fields.One2many('asset.management.return.lines', 'ret_line_id', string="Asset")

@api.multi
    def button_received(self):
        self.state = 'received'

    for x in self.return_ids:
        holder = self.env['asset.asset'].search([('serial', '=', x.ret_serial_id)])
        for i in holder:
            i.write({'asset_condition': x.ret_condition_id.id})
            print 'pumasok return'

I created a for loop that will scan all serial on my asset.asset module that will equal on my data, then override the data on the field asset_condition equals to my current data

sorry for my bad english