This question has been flagged

There's probably a better way of doing this...

We're trying to modify our Sale Order Tree to have either a single column or multiple columns that will show which state each part of the selling process we are in. To be specific, we're interested in seeing the actual state the invoices and delivery orders are in. 

I know that the sale_order_tree view has a field called invoice_status, but this is very misleading as it only says whether or not an invoice has been created, not the state the invoice is in. 

My solution so far is to have two fields inside sale.order model:

(The fields are of type char and are compute)

Name: x_delivery_state_calc
delivery = self.env['stock.picking'].search([('origin','=',self.name)]) self.x_delivery_state = delivery.state

Name: x_invoice_state_calc

invoice = self.env['account.invoice'].search([('origin','=',self.name)]) self.x_invoice_state = invoice.state

This actually gives errors, but it's basically the same as doing (I'm interested in why it does that, but not the main purpose of this question):

for record in self:

invoice = self.env['account.invoice'].search([('origin','=',record['name'])]

record['x_invoice_state'] = invoice.state

Note that the fields I'm writing to are the same, but without the _calc. These fields are readonly selection type with the selection options being the states from both account_invoice.state and stock_picking.state.

I've also tried writing directly to the _calc field, but I know compute fields aren't stored in the database.

No matter how I write the value, I am unable to get those fields to show the data I want (ignore the top one, I manually added that to the database)

The data is available in the shell however, so I'm confused about why it is not available for the GUI

Triggering x_invoice_state_calc does write the data to the field, but not to the database. Is there a way that I can force this? Or is the compute just not happening? 

Ideally we would like for these fields to update to reflect the current state every time that you enter the sale orders tree

Avatar
Discard
Best Answer

There is not a 1:1 relationship between Sales Orders and Delivery Orders and Invoices. You can have one Sales Order, 2 Delivery Orders and 3 Invoices. Perhaps take a step back with this knowledge and reassess. At earlier versions there was 'invoiced_rate' and 'shipped_rate' which would allow a progress bar to be shown. Order is 50% shipped and 100% paid for. Perhaps that would be better?

Avatar
Discard
Author

Thanks for getting back to me. Yes I was aware that there could be multiple invoices and delivery orders, but for our uses there is going to be one of each for every sale order created. After spending a couple days on this problem, we decided to simply add extra menu items in the Sales dashboard that lead to tree views of the invoices and delivery orders. I did check those fields that you suggested and they don't seem to exist in Odoo 9, or maybe I'm checking in the wrong spot