Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Showing Delivery Information on Sales Orders?

By
Qamar Soft
on 1/12/15, 5:50 AM 896 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 !!!

1
Qamar Soft
On 1/16/15, 10:16 AM

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"/>

0
Emad Jaddou
On 3/6/15, 7:33 AM

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

Just a beginner here so please give some details.

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

Qamar Soft
on 3/6/15, 9:34 AM

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?

Emad Jaddou
on 3/6/15, 2:45 PM
0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 1/12/15, 10:57 AM

The field picked_rate no longer exists in v8.

yes I know how to add it ?

Qamar Soft
on 1/12/15, 11:14 AM

It is rather difficult with a new WMS system.

zbik
on 1/12/15, 12:13 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 1/12/15, 5:50 AM
Seen: 896 times
Last updated: 3/16/15, 8:10 AM