This question has been flagged
2 Replies
5872 Views

Currently Work Orders is sorting by what appears to be Sequence Number, which makes it hard to see the state of different MOs. Is it possible to have the Work Order page automatically sort by Manufacturing Order instead? This would make the page much more readable at a glance. Thanks!

Avatar
Discard
Best Answer

Add

_order = 'production_id'

to class mrp_production_workcenter_line

Avatar
Discard
Author

Thanks, that worked for me. Is it possible to have it sort by Manufacturing Order and then sequence? So that the MOs are grouped together but in sequential order? I have tried both _order = 'production_id, sequence' and _order = 'sequence, production_id', but neither of these seem to do what I want. Thanks!

Try add new field: 'sequence_mo': fields.related('production_id', 'sequence', string="Sequence MO", type="integer"), and _order = 'production_id, sequence_mo'

Author

I tried this, but ended up getting an error - ProgrammingError: column "sequence_mo" does not exist. Any resin why that might be? I tried moving the _order line below the _columns line but that didn't work either.

Are you define this field in mrp_production_workcenter_line?

Author

Yeah, definitely. I put my code in a new answer below if you want to take a look.

Author Best Answer

wowas - here is my code:

 

from openerp.osv import osv, fields

class mrp_production_workcenter_line(osv.osv):

    _inherit = 'mrp.production.workcenter.line'

    _order = 'production_id, sequence_mo'

    _columns = {

        'x_company':fields.related('production_id','company_id',type='many2one',relation='res.company',string='Company',readonly=True),

     'sequence_mo':fields.related('production_id','sequence',type='integer',string='Sequence MO'),

        }

Avatar
Discard

I'am sorry, I fogot attr for store to DB. Please try: 'sequence_mo':fields.related('production_id','sequence',type='integer',string='Sequence MO',store=True),

Author

I got: KeyError: "Field 'sequence' does not exist in object 'browse_record(mrp.production, 2)', which make sense because 'sequence' is defined in mrp.workcenter.line, not mrp.production, and 'production_id' is a many2one pointing to mrp.production. I feel like it should work just as _order = 'production_id, sequence' but I don't know if that syntax is correct. Thanks for your help though, let me know if anything else pops in to your head.

Yes, you need define field sequence in mrp.production like in mrp.workcenter.line, if you need sort by MO sequence. If you need sort by WO sequence, then you can use _order = 'production_id, sequence' (It will sort first by field 'name' of MO and then sort by field 'sequence' of WO).