No changes For fields After Write Method

Asked by Ali Abdelmonem Mustafa

Hi All , I Tried To Use Write Method inside Button WorkFlow To Update filed In account.asset.asset Module But no Changes Happened For This Field

And This Is My Code

def action_done(self, cr, uid, ids, context=None): mro_obj = self.pool.get('mro.order') for records_lines_time in mro_obj.browse(cr, uid, ids): Execution_date = records_lines_time.date_execution asset_ids = records_lines_time.asset_id

    assets_obj = self.pool.get('account.asset.asset')
    assets_obj.write(cr,uid,[asset_ids.id],{'last_fixing' : Execution_date},context=context)

    for order in self.browse(cr, uid, ids, context=context):
        self.pool.get('stock.move').action_done(cr, uid, [x.id for x in order.parts_move_lines])
    self.write(cr, uid, ids, {'state': 'done', 'date_execution': time.strftime('%Y-%m-%d %H:%M:%S')})
    return True

Please I Need Help

Thanks A Lot

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Serpent Consulting Services
Solved:
Last query:
Last reply:
Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#1

Ali,

Questions for you!

1. asset_ids = records_lines_time.asset_id : Is asset_id the many2one field?

2. Is asset_id value coming as any ID? If there is a value, the write will get succeeded.

3. With the IDs of current model you are operating on mro.order by using mro_obj.browse(cr, uid, ids). This is wrong if the model is not mro.order

4. You use for order in self.browse(cr, uid, ids, context=context)! Are you using same IDs in current model?

Thanks.

Revision history for this message
Ali Abdelmonem Mustafa (a-abdelmonem) said :
#2

Sorry For The Code

This Is My Code But It Didn't Work

  def action_done(self, cr, uid, ids, context=None):
        mro_obj = self.pool.get('mro.order')
        for records_lines_time in mro_obj.browse(cr, uid, ids):
            Execution_date = records_lines_time.date_execution
            asset_ids = records_lines_time.asset_id

        assets_obj = self.pool.get('account.asset.asset')
        assets_obj.write(cr,uid,[asset_ids.id],{'last_fixing' : Execution_date},context=context)

        for order in self.browse(cr, uid, ids, context=context):
            self.pool.get('stock.move').action_done(cr, uid, [x.id for x in order.parts_move_lines])
        self.write(cr, uid, ids, {'state': 'done', 'date_execution': time.strftime('%Y-%m-%d %H:%M:%S')})
        return True

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#3

Dear Ali,

Please tell us the current model name!

Revision history for this message
Best Serpent Consulting Services (serpent-consulting-services) said :
#4

Ali,

Lets optimise:
1. Remove mro.order pooling.
2. Make sure your move done works ok.
3. Comment it and check.

Thanks.

Revision history for this message
Ali Abdelmonem Mustafa (a-abdelmonem) said :
#5

Thanks Jay For You The Answer Is Like That

  def action_done(self, cr, uid, ids, context=None):
        assets_obj = self.pool.get('account.asset.asset')
        for records_lines_time in self.browse(cr, uid, ids):
            Execution_date = records_lines_time.date_execution
            assets_obj.write(cr,uid,[records_lines_time.asset_id.id],{'last_fixing' : Execution_date})

        self.write(cr, uid, ids, {'state': 'done', 'date_execution': time.strftime('%Y-%m-%d %H:%M:%S')})
        return True

Revision history for this message
Ali Abdelmonem Mustafa (a-abdelmonem) said :
#6

Thanks Serpent Consulting Services, that solved my question.

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#7

Welcome!