{"action":"created","issue":{"url":"https://api.github.com/repos/odoo/odoo/issues/4315","labels_url":"https://api.github.com/repos/odoo/odoo/issues/4315/labels{/name}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/4315/comments","events_url":"https://api.github.com/repos/odoo/odoo/issues/4315/events","html_url":"https://github.com/odoo/odoo/pull/4315","id":52335495,"number":4315,"title":"fix mrp calculation by use of low level code","user":{"login":"scosist","id":8325184,"avatar_url":"https://avatars.githubusercontent.com/u/8325184?v=3","gravatar_id":"","url":"https://api.github.com/users/scosist","html_url":"https://github.com/scosist","followers_url":"https://api.github.com/users/scosist/followers","following_url":"https://api.github.com/users/scosist/following{/other_user}","gists_url":"https://api.github.com/users/scosist/gists{/gist_id}","starred_url":"https://api.github.com/users/scosist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scosist/subscriptions","organizations_url":"https://api.github.com/users/scosist/orgs","repos_url":"https://api.github.com/users/scosist/repos","events_url":"https://api.github.com/users/scosist/events{/privacy}","received_events_url":"https://api.github.com/users/scosist/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"jco-odoo","id":3832699,"avatar_url":"https://avatars.githubusercontent.com/u/3832699?v=3","gravatar_id":"","url":"https://api.github.com/users/jco-odoo","html_url":"https://github.com/jco-odoo","followers_url":"https://api.github.com/users/jco-odoo/followers","following_url":"https://api.github.com/users/jco-odoo/following{/other_user}","gists_url":"https://api.github.com/users/jco-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/jco-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jco-odoo/subscriptions","organizations_url":"https://api.github.com/users/jco-odoo/orgs","repos_url":"https://api.github.com/users/jco-odoo/repos","events_url":"https://api.github.com/users/jco-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/jco-odoo/received_events","type":"User","site_admin":false},"milestone":null,"comments":17,"created_at":"2014-12-18T08:05:43Z","updated_at":"2016-01-26T02:25:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/4315","html_url":"https://github.com/odoo/odoo/pull/4315","diff_url":"https://github.com/odoo/odoo/pull/4315.diff","patch_url":"https://github.com/odoo/odoo/pull/4315.patch"},"body":"Fixes #3626 by generating a low level code to be used when calculating reorder rules.\r\n\r\nAlthough the problem exists with 8.0 (see issue for current and expected behavior), the solution requires data model changes so the PR is on master with the intention that it will be accepted and then merged into 8.0."},"comment":{"url":"https://api.github.com/repos/odoo/odoo/issues/comments/174782123","html_url":"https://github.com/odoo/odoo/pull/4315#issuecomment-174782123","issue_url":"https://api.github.com/repos/odoo/odoo/issues/4315","id":174782123,"user":{"login":"matt454357","id":7604932,"avatar_url":"https://avatars.githubusercontent.com/u/7604932?v=3","gravatar_id":"","url":"https://api.github.com/users/matt454357","html_url":"https://github.com/matt454357","followers_url":"https://api.github.com/users/matt454357/followers","following_url":"https://api.github.com/users/matt454357/following{/other_user}","gists_url":"https://api.github.com/users/matt454357/gists{/gist_id}","starred_url":"https://api.github.com/users/matt454357/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matt454357/subscriptions","organizations_url":"https://api.github.com/users/matt454357/orgs","repos_url":"https://api.github.com/users/matt454357/repos","events_url":"https://api.github.com/users/matt454357/events{/privacy}","received_events_url":"https://api.github.com/users/matt454357/received_events","type":"User","site_admin":false},"created_at":"2016-01-26T02:25:00Z","updated_at":"2016-01-26T02:25:00Z","body":"@jco-odoo, Here's the simplified query.  If you like it, we will update the PR.\r\n\r\n```sql\r\nwith j as (\r\n    -- if only template specified on mrp.bom, then expand list with all variants\r\n    SELECT DISTINCT\r\n        COALESCE(b.product_id,p.id) AS parent_id,\r\n        l.product_id AS comp_id\r\n    FROM mrp_bom_line AS l, mrp_bom AS b, product_product AS p\r\n    WHERE b.product_tmpl_id=p.product_tmpl_id\r\n    AND l.bom_id=b.id\r\n)\r\nSELECT *\r\nFROM (\r\n    -- build a path array\r\n    with recursive stack(parent_id, comp_id, path) as (\r\n        SELECT\r\n            j.parent_id,\r\n            j.comp_id,\r\n            ARRAY[j.parent_id, j.comp_id]\r\n        FROM j\r\n        WHERE j.parent_id NOT IN (SELECT comp_id FROM j)\r\n        UNION ALL\r\n        SELECT\r\n            j.parent_id,\r\n            j.comp_id,\r\n            path || j.comp_id\r\n        FROM stack AS s, j\r\n        WHERE j.parent_id=s.comp_id\r\n    )\r\n    -- use longest path for each orderpoint as llc\r\n    SELECT\r\n        op.id,\r\n        COALESCE(MAX(ARRAY_LENGTH(path, 1))-1, 0) AS llc\r\n    FROM stock_warehouse_orderpoint AS op\r\n    LEFT JOIN stack AS s ON op.product_id=s.comp_id\r\n    GROUP BY op.id\r\n) AS res\r\n```"}}