relations

61 views
Skip to first unread message

Cato Nano

unread,
Jan 16, 2018, 5:02:29 AM1/16/18
to tryton
I have 2 models, with a relation between them

Much like Sales and SaleLine

Let' s say I have Bolletta and BollettaLine

Some BollettaLine fields are calcolated and they depend on some Bolletta fields

How do I do that ?

Also, I' d like to show on the BollettaLine form view some Bolletta fields

I tried this

SomeBollettaField = fields.Many2One('tributi.bolletta', 'Some Bolletta Field')

but when I update the module, I get

psycopg2.ProgrammingError: ERRORE: non è possibile implementare il vincolo di chiave esterna "tributi_affissione_dataCommissione_fkey"
DETAIL: Le colonne chiave "dataCommissione" e "id" hanno tipi incompatibili: date e integer.

Translated:

ERROR: The foreign key constarint tributi_affissione_dataCommissione_fkey can't be implemented
DETAIL: The key columns "SomeBollettaField" and "id" have mismatching types: date and integer

Cato Nano

unread,
Jan 16, 2018, 5:09:15 AM1/16/18
to tryton
ah the field has to be different

I think I made it

Cato Nano

unread,
Jan 16, 2018, 5:15:26 AM1/16/18
to tryton
No I didn' t make it

On the client I see a key error

here it is
https://imgur.com/a/Cwct2

This is how I defined my field

bollettaDataCommissione = fields.Many2One('tributi.bolletta', 'bolletta.dataCommissione')

I guess you could read it as

SomeBollettaField = fields.Many2One('tributi.bolletta', 'bolletta.bollettaField')

Sergi Almacellas Abellana

unread,
Jan 16, 2018, 5:40:47 AM1/16/18
to try...@googlegroups.com
El 16/01/18 a les 11:02, Cato Nano ha escrit:
> I have 2 models, with a relation between them
>
> Much like Sales and SaleLine
>
> Let' s say I have Bolletta and BollettaLine
>
> Some BollettaLine fields are calcolated and they depend on some Bolletta fields
>
> How do I do that ?
>
> Also, I' d like to show on the BollettaLine form view some Bolletta fields
>
> I tried this
>
> SomeBollettaField = fields.Many2One('tributi.bolletta', 'Some Bolletta Field')
>

You have to create a function fields which is updated via
on_change_with. For example the product_uom_category [1]on the sale
lines uses the value from the product relation.

[1] http://hg.tryton.org/modules/sale/file/3414b8d97403/sale.py#l1057


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

Cato Nano

unread,
Jan 17, 2018, 1:55:23 AM1/17/18
to tryton
Il giorno martedì 16 gennaio 2018 11:40:47 UTC+1, Sergi Almacellas Abellana ha
>
> You have to create a function fields which is updated via
> on_change_with. For example the product_uom_category [1]on the sale
> lines uses the value from the product relation.
>
> [1] http://hg.tryton.org/modules/sale/file/3414b8d97403/sale.py#l1057
>
>
> --


Thank you Sergi

This is the situation:

bollettaDataCommissione = fields.Function(fields.Many2One('tributi.bolletta', 'Data di Commissione'), 'on_change_with_bollettaDataCommissione')

@fields.depends('bolletta')
def on_change_with_bollettaDataCommissione(self, name=None):
if self.bolletta:
return self.bolletta.dataCommissione


and I get

can't compare datetime.date to int

Cato Nano

unread,
Jan 17, 2018, 1:57:29 AM1/17/18
to tryton
This is on BollettaLine, of course

Cato Nano

unread,
Jan 17, 2018, 2:20:45 AM1/17/18
to tryton
Aaah it' s like this

bollettaDataCommissione = fields.Function(fields.Date('tributi.bolletta', 'Data di Commissione'), 'on_change_with_bollettaDataCommissione')

Cato Nano

unread,
Jan 17, 2018, 2:51:36 AM1/17/18
to tryton
Il giorno mercoledì 17 gennaio 2018 08:20:45 UTC+1, Cato Nano ha scritto:

> Aaah it' s like this
>
> bollettaDataCommissione = fields.Function(fields.Date('tributi.bolletta', 'Data di Commissione'), 'on_change_with_bollettaDataCommissione')
>
> @fields.depends('bolletta')
> def on_change_with_bollettaDataCommissione(self, name=None):
> if self.bolletta:
> return self.bolletta.dataCommissione

The date field works, but where' s my label ?

The field name is shown instead of the field string, as you can see here

https://imgur.com/a/tu5fL

Sergi Almacellas Abellana

unread,
Jan 17, 2018, 3:32:12 AM1/17/18
to try...@googlegroups.com
El 17/01/18 a les 08:51, Cato Nano ha escrit:
> Il giorno mercoledì 17 gennaio 2018 08:20:45 UTC+1, Cato Nano ha scritto:
>
>> Aaah it' s like this
>>
>> bollettaDataCommissione = fields.Function(fields.Date('tributi.bolletta', 'Data di Commissione'), 'on_change_with_bollettaDataCommissione')
>>
>> @fields.depends('bolletta')
>> def on_change_with_bollettaDataCommissione(self, name=None):
>> if self.bolletta:
>> return self.bolletta.dataCommissione
> The date field works, but where' s my label ?

The label used is the string of the target field. In a date field, this
is the first argument. In your case is 'tributi.bolleta'. You should
update the field definition to show the correct label.

Cato Nano

unread,
Jan 21, 2018, 4:30:17 AM1/21/18
to tryton
Thank you Sergi
I' ll try and report back

Cato Nano

unread,
Jan 23, 2018, 11:52:44 AM1/23/18
to tryton
I tried and it works

Thanks
Reply all
Reply to author
Forward
0 new messages