Skip to Content
Menu
This question has been flagged
3 Replies
2767 Views

    @api.multi

    def action_on_confirm(self):

        partner_object= self.env['res.partner'].search([('id', '=', self.partner_id.id)])

       for order in self:

            if order.state == 'sale':

                partner_object.write ({'last_saleorder_date': order.date_order})

        return super(SaleOrder,self).action_on_confirm(self)

The above  code is written in sale.order and not working.
Avatar
Discard
Best Answer

    Please try the following code in action confirmation button action.


       for order in self: 

                order.partner_id.last_saleorder_date = order.date_order

 

Avatar
Discard
Best Answer

1. The action name should be action_confirm - not action_on_confirm
2. You do not need to perform a search operation for a partner, this object is already available in the sale_order record
3. The second self parameter should not be used in the super
4. State 'sale' is set after (not before) calling action_confirm
  
@api.multi
def action_confirm(self):
    ret = super(SaleOrder,self).action_confirm()   
    for order in self:
        if order.state == 'sale':
            order.partner_id.write ({'last_saleorder_date': order.date_order})
    return ret

Avatar
Discard
Best Answer

Hello,

Here no need to search operation for a partner object. you can use partner_id field which already available in sale.order object.

you can add below code in your function:

    for order in self:
        if order.state == 'sale':
            order.partner_id.write ({'last_saleorder_date': order.date_order})

OR  You can used below:

    for order in self:
        if order.state == 'sale':
            order.partner_id.last_saleorder_date = order.date_order

Thank you.
Avatar
Discard
Author

Both works fine.