El 15/02/17 a les 16:50, Ul ha escrit:
Am 15.02.2017 um 15:52 schrieb Sergi Almacellas Abellana:
El 15/02/17 a les 15:29, Ul ha escrit:

Thanks for sharing,

How do you define the stock_lot_relation table?

as a usual Table in the database:

class LotRelation(ModelSQL, ModelView):
    "Lot Relation"
    __name__ = 'stock.lot.relation'
    _rec_name = 'from_lot'
    from_lot = fields.Many2One('stock.lot', 'from Lot', required=True)
    quantity = fields.Float("Quantity", required=True,
        digits=(16, Eval('unit_digits', 2)), depends=['unit_digits'])
    uom = fields.Many2One("product.uom", "Uom", required=True)
    to_lot = fields.Many2One('stock.lot', 'to Lot', required=True)

I think this is the table that we can add to the main stock_lot module
and this table can be computed with a table query by joining the inputs
and the outputs of a production.

If relations only originate from productons, this can be computed from
the production table. But i want to populate it from shipment in too,
because i want to create a new internal lot with every shipment and
relate it to the lot of the supplier.
This has two reasons:
- if we get several shipments from on supplier that have the same
lot-number because the supplier produced it at once, i want to be able
to track down our lot witch shipment it came with.
- some suppliers have incredibly long lot-numbers and it's annoying to
type them every time you use it.

Well, that will be also possible if you use a UNION query to join data from productions and from shipments. Indeed all the data is in the stock move table but it have to be joined in a different way (one using the shipment field and the other using the production fields). Something like:

select output.id, input.lot as from_lot, output.lot as to_lot
FROM stock_move input
INNER JOIN stock_move output ON input.shipment = output.shipment and input.product = output.product and input.to_location = output.to_location and input.lot <> output.lot
UNION
select output.id, input.lot as from_lot, output.lot as to_lot
FROM stock_move input
INNER JOIN stock_move output ON input.production_input = output.production_output and input.product = output.product and input.to_location = output.to_location and input.lot <> output.lot

Does this work for you?



so as Lot3 is used twice the lines with relation.id 11 and 12 show up
twice.


The problem is that the same id is returned for multiple records. The id
field of every model must be unique (as it's used to identify the
records). Indeed, you developing a table_query you are supposed to take
care about it. My advice is to compute the record id by using the ids of
the composed lots.
The problem is, that it is literally the same rows in the joined table
that are returned twice by the query. using the lot id won't help
anything, Lot3 is used 2 times and all lines within it are exactly the
same.
The only way would be to have some kind of counter or sequence in the
with-clause. But i didn't find a function that could do that. Any other
way like adding the depth of recursion and the relation id could also
give duplicates.
And i don't see any value such an id would add except fulfilling the
rule that the ids of every returned line have to be unique. There is no
information added by giving different ids, its even information lost:
the information that it is the very same line in the originating table.


Indeed, instead of building the full tree, I'm wondering if it will be enough to add a relate option to open the parent and children records in a new window. This will provide the same information in a simpler way.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

--
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/4fd52cdd-3112-6332-3254-78c7daae73f3%40koolpi.com.

Reply via email to