Skip to Content
Menu
This question has been flagged
1 Reply
2659 Views

Dear Odoo users,

Currently, I defaulted my Purchase menu view to 'Kanban' and grouped it by Status. I noticed that it was filtered in alphabetical order, not the sequence the status should be in. It would make sense if the order from left to right was RFQ > RFQ Sent > Purchase Order as those are the steps you follow. However, it now is RFQ > Purchase Order > RFQ Sent, while the actual sequence from the status is in the correct order as seen in Field > Status (purchase.order) or simply in the top right of an order it is seen the order is correct. (Same goes for Sales)

How could I get this order in my Kanban view? I tried going for the easy solution and changing 'sent' to 'draft sent' in the Field as it would alphabetically be behind 'draft' but before 'purchase'. However, it is not possible to change a base field. The best-case scenario would be to not change anything and just view the correct status in chronological order (sequence) instead of alphabetical order.

Does anyone have a Python solution to change my base field value name? Or preferably another solution in general to obtain my wish to view the sequence in the correct order via Kanban view? 


Kind regards,

Marco


Avatar
Discard
Best Answer

Hi,
It is not a good method, if we override the default state selection field, because its values are directly called in many functions in odoo. So a better approach would be you can define a new selection field similar to the 'state' just for the group by purpose. For this new field define the values alphabetically as per our need. Define a default and compute function for this field to map from the original 'state' field. Then group by the kanban view based upon the new field.

Sample code:

class PurchaseOrder(models.Model):
    _inherit = "purchase.order"

    def _default_new_state(self):
        for rec in self:
            if rec.state == 'draft':
                rec.new_state = 'a_draft'
            elif rec.state == 'sent':
                rec.new_state = 'b_sent'
            elif rec.state == 'to approve':
                rec.new_state = 'c_to approve'
            elif rec.state == 'purchase':
                rec.new_state = 'd_purchase'
            elif rec.state == 'done':
                rec.new_state = 'e_done'
            else:
                rec.new_state = 'f_cancel'

    new_state = fields.Selection([
        ('a_draft', 'RFQ'),
        ('b_sent', 'RFQ Sent'),
        ('c_to approve', 'To Approve'),
        ('d_purchase', 'Purchase Order'),
        ('e_done', 'Locked'),
        ('f_cancel', 'Cancelled')
    ], string='New Status', readonly=True, store=True, index=True, copy=False, compute='_compute_new_state',
    default=_default_new_state)

    @api.depends('state')
    def _compute_new_state(self):
        for rec in self:
            if rec.state == 'draft':
                rec.new_state = 'a_draft'
            elif rec.state == 'sent':
                rec.new_state = 'b_sent'
            elif rec.state == 'to approve':
                rec.new_state = 'c_to approve'
            elif rec.state == 'purchase':
                rec.new_state = 'd_purchase'
            elif rec.state == 'done':
                rec.new_state = 'e_done'
            else:
                rec.new_state = 'f_cancel'

Regards

Avatar
Discard
Author

Hi Cybrosys, Thank you kindly. The solution seems very very good. Did not think of it that way. However, I cannot get it to work. When I group it by 'New Status' it just shows all orders under 'false', not per RFQ, RFQ Sent, PO. So the new field I made as you said is named; x_state, name; New Status, Model; Purchase Order and Field Type; selection. Base properties is Read Only, Indexed and Stored. The selection options are a_draft etc. Your code is under 'Compute' and the Dependencies is 'state'. What am I doing wrong?

Related Posts Replies Views Activity
1
Mar 22
2446
4
Nov 20
3850
3
Aug 15
6962
2
Oct 23
1760
1
Jan 22
1304