{"action":"created","issue":{"url":"https://api.github.com/repos/odoo/odoo/issues/8537","labels_url":"https://api.github.com/repos/odoo/odoo/issues/8537/labels{/name}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/8537/comments","events_url":"https://api.github.com/repos/odoo/odoo/issues/8537/events","html_url":"https://github.com/odoo/odoo/issues/8537","id":106551224,"number":8537,"title":"[8.0] Too many calculations on price_subtotal field on sale.order.line","user":{"login":"hugosantosred","id":200092,"avatar_url":"https://avatars.githubusercontent.com/u/200092?v=3","gravatar_id":"","url":"https://api.github.com/users/hugosantosred","html_url":"https://github.com/hugosantosred","followers_url":"https://api.github.com/users/hugosantosred/followers","following_url":"https://api.github.com/users/hugosantosred/following{/other_user}","gists_url":"https://api.github.com/users/hugosantosred/gists{/gist_id}","starred_url":"https://api.github.com/users/hugosantosred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugosantosred/subscriptions","organizations_url":"https://api.github.com/users/hugosantosred/orgs","repos_url":"https://api.github.com/users/hugosantosred/repos","events_url":"https://api.github.com/users/hugosantosred/events{/privacy}","received_events_url":"https://api.github.com/users/hugosantosred/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-15T13:06:47Z","updated_at":"2015-09-15T15:11:27Z","closed_at":null,"body":"We are experiencing issues when saving big sale orders (~ 500 Lines) it always throws a CPU Time limit Exceeded error.\r\n\r\nDebugging this I've noticed than price_subtotal field is recomputed too many times (Also I tested with a database with demo data and only sale module installed)\r\n\r\nI've put a logger in _amount_line in sale.py and for a 2 line sale order is doing this:\r\n\r\n```\r\n2015-09-15 12:46:15,900 11808 WARNING test_big_so openerp.addons.sale.sale: AMOUNT LINE [15, 798]\r\n2015-09-15 12:46:15,947 11808 WARNING test_big_so openerp.addons.sale.sale: AMOUNT LINE [15, 798]\r\n2015-09-15 12:46:15,963 11808 WARNING test_big_so openerp.addons.sale.sale: AMOUNT LINE [15, 798]\r\n2015-09-15 12:46:16,236 11808 WARNING test_big_so openerp.addons.sale.sale: AMOUNT LINE [15, 798]\r\n```\r\n\r\nSo if the order has 500 lines, when saving it, will block the ERP in multiple workers mode or it will spend nearly a half hour on saving this sale order.\r\n\r\nTo reproduce this behaviour:\r\n- Create a new sale order\r\n- Add many lines to it and save the order (This time this error is not going to happen and the order will save as expected)\r\n- Change the fiscal position in the order, so it will update the taxes on all the lines\r\n- Save the order again. (Now it's going to spend a lot of time calculating amount_line in the order)\r\n\r\n\r\nAnyone else has noticed this behaviour?"},"comment":{"url":"https://api.github.com/repos/odoo/odoo/issues/comments/140424282","html_url":"https://github.com/odoo/odoo/issues/8537#issuecomment-140424282","issue_url":"https://api.github.com/repos/odoo/odoo/issues/8537","id":140424282,"user":{"login":"rvalyi","id":16926,"avatar_url":"https://avatars.githubusercontent.com/u/16926?v=3","gravatar_id":"","url":"https://api.github.com/users/rvalyi","html_url":"https://github.com/rvalyi","followers_url":"https://api.github.com/users/rvalyi/followers","following_url":"https://api.github.com/users/rvalyi/following{/other_user}","gists_url":"https://api.github.com/users/rvalyi/gists{/gist_id}","starred_url":"https://api.github.com/users/rvalyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvalyi/subscriptions","organizations_url":"https://api.github.com/users/rvalyi/orgs","repos_url":"https://api.github.com/users/rvalyi/repos","events_url":"https://api.github.com/users/rvalyi/events{/privacy}","received_events_url":"https://api.github.com/users/rvalyi/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T15:11:27Z","updated_at":"2015-09-15T15:11:27Z","body":"@hugosantosred yes on 6.1 already ;-) ...\r\nSo basically we had a module recomputing the taxes on fiscal position changes because it was not native by that time. The problem was each time something was changed at the line level, it would recompute stored fields at the order level. We avoided that by setting a special context key while writing to the line and disabled computed fields computation with an ORM patch when that key was found in the context. That is context key is now native in the ORM but I forgot its name. I guess the new API is having the same trouble under the hood when you change a fiscal position (not sure if it has been recently implemented) so may be it's worth investigating if the same kind of fix would work.\r\n\r\nIn any case you are right, that would be cool Odoo to be tested with large orders and not only 2 lines orders to avoid these issues. I m curious about your feedback if you manage to work around it."}}