Conversation
There was a problem hiding this comment.
Shouldn't this be ids[x[0] for x in ...]?
There was a problem hiding this comment.
no, look closely for the comma
There was a problem hiding this comment.
Ah, a bit weird syntax, but OK, you're right
There was a problem hiding this comment.
the weird syntax is actually slightly faster - compare
python -m timeit '[x for x, _ in [(y, y) for y in range(100000)]]'
and
python -m timeit '[x[0] for x in [(y, y) for y in range(100000)]]'
There was a problem hiding this comment.
Noted for future list comprehension that I make.
There was a problem hiding this comment.
this can also be helpful in a normal loop when you iterate over a huge result set, but do quite little per iteration. Then
for a, b, c, d in cr.fetchall()
performs better than
for row in cr.fetchall()
if within the loop, all values of row are used
There was a problem hiding this comment.
Thanks for the info. The problem is if the list if very huge or you don't know all possible values (in a select * statement), but obviously that cases can be always contained.
49ed420 to
b4a6a78
Compare
8a9bb87 to
19e16d8
Compare
[FIX] we did it the wrong way around
88b2082 to
e5a49b4
Compare
|
It might speed things up even more if you first add all the fields to a table and then fill the values with one statement. Now you have to go several times to all or most of the sale orders and lines. |
|
yes, good point. But at the moment I'm busy with a general speedup of recomputations of which I promise myself much more performance gains, because something is fishy here. It runs currently for testing purposes, afterwards I'll propose this to upstream, OCB and here hbrunn/OCB@25e5f95 There are two problems with current recomputation: The time used grows nonlinear, that's a problem with my 300k sale order lines. Additionally, what makes this hard to debug is that there's some nondeterminism going on, two times recomputing the same field on the same rows yields a different execution path (or the same, that's up to chance). |
|
Apart from the general rewrite of recomputation you might also look at this PR: #735 |
| cr.execute( | ||
| """\ | ||
| update sale_order_line | ||
| set qty_to_invoice=product_uom_qty - qty_invoiced |
There was a problem hiding this comment.
@hbrunn This sql sentence is not correct. It does not replicate the same conditions as https://github.com/odoo/odoo/blob/9.0/addons/sale/sale.py#L516
For example, in products where the invoice policy is set based on delivered quantities the quantity to invoice is to be based on the quantity delivered - quantity invoiced.
| """\ | ||
| update sale_order_line | ||
| set invoice_status=( | ||
| case when qty_to_invoice<=0 then 'invoiced' |
There was a problem hiding this comment.
replace with case when coalesce(qty_to_invoice,0)<=0 then 'invoiced'
| """\ | ||
| update sale_order_line | ||
| set qty_to_invoice=product_uom_qty - qty_invoiced | ||
| where qty_invoiced is not null |
There was a problem hiding this comment.
This where condition is not correct. Instead use:
update sale_order_line
set qty_to_invoice=product_uom_qty - coalesce(qty_invoiced,0)
This issue has been giving me a hard time.
|
@jbeficent thanks for you input, done. Next time, just create a PR |
|
What is the status of this? |
|
I'm waiting for @jbeficent to test the last commit where I integrated his points |
|
@jbeficent can you review? Travis is red anyway. |
| """\ | ||
| update sale_order_line | ||
| set qty_to_invoice=case | ||
| when pt.invoice_policy = 'order' then |
There was a problem hiding this comment.
invoice_policy field in product.template doesn't exists in pre-migration.py because it's a new field in 9.0 version If you move this query to post-migrations it works
|
@jbeficent please feedback about this PR. @hbrunn check last comment and red status |
|
@pedrobaeza last comment defeats the purpose of the pr, the code is fixed but travis is acting up |
|
Again the TRAVIS_COMMIT error, so I close and reopen the PR for forcing a correct build. |
| def prepopulate_fields(cr): | ||
| """ Recomputing a fields will be very expensive via the ORM, so do it | ||
| here for fields where the computation is trivial""" | ||
| cr.execute('alter table sale_order_line add column qty_invoiced numeric') |
| set qty_invoiced=line2qty_invoiced.qty_invoiced | ||
| from line2qty_invoiced where line2qty_invoiced.id=sale_order_line.id | ||
| """) | ||
| cr.execute('alter table sale_order_line add column qty_to_invoice numeric') |
There was a problem hiding this comment.
ADD set default=product_uom_qty
There was a problem hiding this comment.
About this PG says: cannot use column references in default expression
There was a problem hiding this comment.
From PG doc:
DEFAULT default_expr
The DEFAULT clause assigns a default data value for the column whose column definition it appears within. The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). The data type of the default expression must match the data type of the column.
The default expression will be used in any insert operation that does not specify a value for the column. If there is no default for a column, then the default is null.
There was a problem hiding this comment.
OK, I didn't know. Then we should still keep here 2 sentences
There was a problem hiding this comment.
I'm working on hbrunn#5. I hope next week this can be merged.
| where l.order_id=o.id | ||
| """) | ||
| cr.execute('alter table sale_order_line add column invoice_status varchar') | ||
| cr.execute("update sale_order_line set invoice_status='no'") |
There was a problem hiding this comment.
Instead of this, just add in the previous statement set default='no'
| where state in ('sale', 'done') | ||
| """) | ||
| cr.execute('alter table sale_order add column invoice_status varchar') | ||
| cr.execute("update sale_order set invoice_status='no'") |
|
Should we merge this? |
|
I'm testing this today. I'll be reporting later (tomorrow perhaps) |
|
TL;DR It seems this is incorrect. ExperimentI took a DB with Odoo 8, and clone it twice: Then I migrated the However comparing the resulting For instance, the field The first thing I notice is that where the However, we still have a lot of differences: Let's see some records that differ: For the record 38, the speedier version computes 15 while the normal version computes 0. Other fields show as much differences as well. I'll try to look at these differences and see if I can spot the issue. |
The Python implementation tests for the invoice's type being other than 'cancel'.
|
I pushed 8625c10 to fix the qty_invoiced amount. |
|
can you PR this to this PR's branch? Then I'll merge this in this PR. If you want to speed up getting this merged, you can check @pedrobaeza's comments to. I won't have time to address them any time soon. |
|
I already did: hbrunn#4 |
[FIX] SQL computation for sale.order.line.qty_invoice.
|
I'll be addressing @pedrobaeza's comments soon. |
|
See PR hbrunn#5 |
|
I created another PR to the original branch. It addresses @pedrobaeza's
requests. One of the requested defaults cannot be set by SQL.
|
|
Still working on this. The field |
|
Any news on this? |
|
I've been unable to keep working on this for the past weeks. We're heavily busy migrating ~50 addons to Odoo 9 and then to Odoo 10. After they all migrated to 9, I could try another round of DB migration and see if I could work on this. |
|
OK, let me know. I don't see this as critical because times are more or less manageable in my cases, but maybe with a lot of sale orders it's not the same. |
|
Closing this due to errors on the migration. If anyone wants to continue this experiment, can take this code and go on with the needed changes, proposing the new alternative. |
Description of the issue/feature this PR addresses:
Current behavior before PR:
Desired behavior after PR is merged:
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr