This question has been flagged
3 Replies
4571 Views

I have two modules, each  have their own  state. I am trying to change state of other  module's specific  record. But my code  changes  the state  of every record  in  that class.  How  can i change state of only  the specified record.

My class look like this

@api.multi
def _create_load_up(self):
if self.state=='load':
inv_obj = self.env['loading.slip']
rec=inv_obj.search(self.so_no=='so_no')
if rec:
slip=rec.update({
'state':'load'
})
return slip
here I am trying o change the state of loading.slip table to load state when so_no are same of both table( recent table and loading_slip table)
But this changes every record's state to load in loading.slip.
Avatar
Discard

Hi ,

As you told that all the record get updated there it should generate singleton error as per your code. make sure that search method returns a single record. If the search method returns more than one record please use for loop to update the state.

Also the search method is wrong, i mean the syntax. You can correct it as Amal or jignesh mentioned

Author

Thank you guys for your reply, I have implemented the recommended method but when i use this method, before model changes its state to load, loading_slip model auto changes its state to load(i.e _create_load_up method is initially called what can i do for that.

Try changing method name to "create_load_up", also please check are you calling this function from any where

Best Answer

Hi, I have two module which names are freight_forwarder and comparitive _statement i want to change state of one module to behalf of other module state how i can do it

Avatar
Discard
Best Answer

Hello Sarina,


Try this :-

@api.multi

def _create_load_up(self):
    if self.state == 'load':
        rec=self.env['loading.slip'].search([('so_no', '=', self.so_no)])
        if rec:
            rec.state = 'load'


hope it will helps you.

Thanks,

Avatar
Discard
Best Answer

Hello,

I believe by module you mean model

your search function syntax is wrong

use this

rec=inv_obj.search([('field_in_model_rec', '=', 'value')

here I believe it should be 

('so_no', '=', self.so_no)
Avatar
Discard