El 05/05/16 a les 17:35, Clemens Hupka ha escrit:
Hello!

I'm working on a ticket reservation and selling system based on tryton 3.8.

As discussed with pokoli on #tryton, my model is quite special because i
have two one2many-relations towards ticket.ticket (one from
ticket.reservation and one from ticket.sale).

Here is the link to the discussion on the irc:

http://www.tryton.org/~irclog/2016-05-05.log.html#t2016-05-05%2015:09

The goal was to get all tickets of a reservation into a sale with the
following on_change function (the number of tickets in the system should
be kept constant). The problem is, that with this piece of code the
number of reserved ticket is newly created, so if i select a reservation
with tickets id:162 and id:163 it creates me two new empty tickets
instead of updating the reserved ones...

As shown in the irclog, this Returns:

  [{'tickets': defaultdict(<type 'list'>, {'add': [(0, {}), (1, {})]})}]

To the client code, because the records have no modified property.
So I'm wondering if we should at least return the id in order to relate already existing records.


Here is the code:

class Ticketsale(ModelSQL, ModelView):
     """
    Ticket sale
    """
     __name__ = 'ticket.sale'
     receipt_number = fields.Char('Receipt number', readonly=True,
select=True)
     pos_create_date = fields.DateTime('Create date', readonly=True)
     reservation = fields.Many2One('ticket.reservation', 'Reservation')
     voucher = fields.Many2One('ticket.voucher', 'Voucher')
     tickets = fields.One2Many('ticket.ticket', 'sale', "Tickets")
     @fields.depends('reservation','tickets')
     def on_change_reservation(self):
         if self.reservation:
             tkts = list(self.tickets)
             for t in self.reservation.tickets:
                 tkts.append(t)
             self.tickets = tuple(tkts)

I already found another solution with the use of a button. Just wanted
to know (btw pokoli too) if the behaviour of tryton is correct in that
(indeed very special and uncommon) case.

Kind regards,
Clemens Hupka.

--
You received this message because you are subscribed to the Google
Groups "tryton-dev" group.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tryton-dev/675c1ae1-becd-4036-8efb-a704942baf9a%40googlegroups.com
<https://groups.google.com/d/msgid/tryton-dev/675c1ae1-becd-4036-8efb-a704942baf9a%40googlegroups.com?utm_medium=email&utm_source=footer>.


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

--
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/572B6A21.4010508%40koolpi.com.

Reply via email to