On 2017-03-09 12:46, Ul wrote: > My query now looks like: > SELECT (("a"."id" << 5) + "b"."id") AS "id", "a"."create_uid" AS > "create_uid", "a"."create_date" AS "create_date", > "a"."write_uid" AS "write_uid", "a"."write_date" AS > "write_date", "a"."uom" AS "uom", "a"."quantity" AS "quantity", > "a"."lot" AS "from_lot", "b"."lot" AS "to_lot" > FROM "stock_move" AS "a" > INNER JOIN "stock_move" AS "b" > ON ("a"."production_input" = "b"."production_output") > WHERE (("a"."lot" > 0) AND ("b"."lot" > 0)) > UNION > SELECT (("a"."id" << 5) + "a"."id") AS "id", "a"."create_uid" AS > "create_uid", "a"."create_date" AS "create_date", "a"."write_uid" > AS "write_uid", "a"."write_date" AS "write_date", "a"."uom" AS > "uom", "a"."quantity" AS "quantity", "a"."supplier_lot" AS > "from_lot", "a"."lot" AS "to_lot" > FROM "stock_move" AS "a" > WHERE (("a"."lot" > 0) AND ("a"."supplier_lot" > 0))
I still do not see the point to make an union. Your first select could be just the table of a Many2Many relation and you just show the moves as a tree using this Many2Many. And of course you have the reverse Many2Many to go the other way. For the unique id, it is pretty simple to generate unique id with fixed number of ids, see model.Union.union_shard. Also I do not see the point of the clause "lot > 0", if you want just move with lot, use must use "lot IS NOT NULL". But I think it is good to have the tree even if there is not lot. -- Cédric Krier - B2CK SPRL Email/Jabber: cedric.kr...@b2ck.com Tel: +32 472 54 46 59 Website: http://www.b2ck.com/ -- You received this message because you are subscribed to the Google Groups "tryton" group. To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/20170309121729.GN28339%40tetsuo.