This question has been flagged
3 Replies
4275 Views

I would like to add field picked_rate in sale.order.tree to show the  (%) of delivered

I used the answer  https://www.odoo.com/forum/help-1/question/showing-delivery-information-status-carrier-ref-backorders-on-sales-orders-29603

but the field picked_rate doesn't exist in sale.order !!!

Avatar
Discard
Author Best Answer

here is the solution

class sale_order(osv.osv):
    _inherit = 'sale.order'
    
    def _picked_rate(self, cr, uid, ids, name, arg, context=None):
        if not ids:
            return {}
        res = {}
        tmp = {}
        for i in ids:
            tmp[i] = {'picked': 0.0, 'total': 0.0}
        cr.execute(''' SELECT s.id AS sale_order_id,sum(sm.product_uom_qty) AS nbr, sm.state AS move_state, spt.code AS picking_type
             FROM sale_order s
              LEFT JOIN procurement_group p ON (p.id=s.procurement_group_id)
              LEFT JOIN stock_picking sp ON (sp.group_id=p.id)
              LEFT JOIN stock_move sm ON (sm.picking_id=sp.id)
              LEFT JOIN stock_picking_type spt on (spt.id=sp.picking_type_id)
              WHERE s.id IN %s GROUP BY sm.state,s.id,spt.code ''', (tuple(ids),))
         
        for item in cr.dictfetchall():
            if item['move_state'] == 'cancel':
                continue
         
            if item['picking_type'] == 'incoming':  # this is a returned picking
                tmp[item['sale_order_id']]['total'] -= item['nbr'] or 0.0  # Deducting the return picking qty
#                 if item['procurement_state'] == 'done' or item['move_state'] == 'done':
                if  item['move_state'] == 'done':
                    tmp[item['sale_order_id']]['picked'] -= item['nbr'] or 0.0
            else:
                tmp[item['sale_order_id']]['total'] += item['nbr'] or 0.0
#                 if item['procurement_state'] == 'done' or item['move_state'] == 'done':
                if  item['move_state'] == 'done':
                    tmp[item['sale_order_id']]['picked'] += item['nbr'] or 0.0
 
        for order in self.browse(cr, uid, ids, context=context):
            if order.shipped:
                res[order.id] = 100.0
            else:
                res[order.id] = tmp[order.id]['total'] and (100.0 * tmp[order.id]['picked'] / tmp[order.id]['total']) or 0.0
        return res  

    _columns = {
        'picked_rate': fields.function(_picked_rate, method=True, string='Picked', type='float'),
}

then and override the sale.order.tree view and add:

<field name="picked_rate" widget="progressbar" string="Shipped"/>

Avatar
Discard
Best Answer

The field picked_rate no longer exists in v8.

Avatar
Discard
Author

yes I know how to add it ?

It is rather difficult with a new WMS system.

Best Answer

Where exactly do you add this code to add this field?

Just a beginner here so please give some details.

Avatar
Discard
Author

create new model or you can add the to the sale modules

I can define the variable in the sales model. I tried all field type, but I cannot find any that allow to input the above function. Can someone give a more detailed way to achieve this?