Am 22.02.2017 um 09:39 schrieb Sergi Almacellas Abellana:
> El 17/02/17 a les 00:00, Ul ha escrit:
>> but i have to take care, that there is not more than one output with a
>> lot in every production or i will get double ids again.
>> Do you know how to generate new ids in a query?
> 
> Indeed that's the hard part of this code. I'm wondering if you have
> managed to solve it.
> 
In the first approach, i checked the output moves in validation of
production, allowing only one lot in the output of each production.

Now i calculate a new id from the ids of the input and output moves:
i shift the id of the input move 5 bits to the left, than i add the id
of the output move.
As the moves are idiomatically created, they should be in sequence and
at least within one production i think there can't be doubles. Having a
big database there still could theoretically be double ids, but i hope
it is rare enough to ignore it for now.
Of cause i would be happy if anyone finds a better method, or can
confirm that this method is reasonably save.

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))


Regards,
Ulrich

-- 
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/e3a70233-2d22-435b-f344-909234277d6a%40gmx.de.

Reply via email to