On 28/03/13 04:17 -0700, Matthias Kracke wrote:
> Hi,
> 
> I extended for a customer the product_template. Now I want to save all 
> changes made by the user. Here is my setup:
> 
> SaleLine extension:
> 
>     customs_tariff_number = fields.Char('Customs Tariff No.',
>                                  states={
>                                 'invisible': Eval('type') != 'line'},
>                                  on_change=['customs_tariff_number', 
> 'product'],
>                                  depends=['type']
>                                 )
> 
>     def on_change_customs_tariff_number(self, vals):
>         product_obj = Pool().get('product.product')
>         product_id = vals.get('product')
>         if product_id:
>             product = product_obj.browse(product_id)
>             p_template = product.template 
>             p_template.write(p_template.id, {
>                 'customs_tariff_number': vals.get('customs_tariff_number')
>                 })
> 
>         return vals
> 
> and the product template:
> 
>     customs_tariff_number = fields.Char('Customs Tariff No.')
> 
> All I get is:
> 
> sql:Wrong SQL: UPDATE "product_template" SET "customs_tariff_number" = 
> '986543',write_uid = 1,write_date = '2013-03-28T12:02:54.181374'::timestamp 
> WHERE ((id IN (1)))
> 
> The error occurs in trytond/backend/postgresql/database.py for:
> 
> res = self.cursor.execute(sql, params)
> 
> with:
> (Pdb) sql
> 'UPDATE "product_template" SET "customs_tariff_number" = %s,write_uid = 
> %s,write_date = %s WHERE ((id IN (%s)))'
> (Pdb) params
> [u'986543', 1, datetime.datetime(2013, 3, 28, 12, 2, 54, 181374), 1]
> 
> Funny thing is, if I try the sql statement in pgAdmin3 everything works 
> like expected.
> 
> Where is my mistake? What should I check?

on_change calls are readonly.
I don't think there is any valid reason to write the on_change value in
the database as you did. It will be written once the user decide to save
his changes.

-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpbFTARQg1Kq.pgp
Description: PGP signature

Reply via email to