Hi,
I have 2 classes (HEADER and LINES)
HEADER has a function field currency (because currency need to be stored on the LINES):
currency = fields.Function(fields.Many2One('currency.currency', 'Default Currency',
states=_STATES, depends=_DEPENDS),'on_change_with_currency')
...
@fields.depends('party','company')
def on_change_with_currency(self, name=None):
cursor = Transaction().connection.cursor()
Purchase = Pool().get('purchase.purchase')
table = Purchase.__table__()
if self.party:
subquery = table.select(table.currency,
where=table.party ==
self.party.id,
order_by=
table.id,
limit=10)
cursor.execute(*subquery.select(subquery.currency,
group_by=subquery.currency,
order_by=Count(Literal(1)).desc))
row = cursor.fetchone()
if row:
currency_id, = row
return currency_id
#cls.currency_digits = self.currency.digits
elif self.company:
return
self.company.currency.id return None
LINES has also a currency field but a many2one (with as default value, currency from HEADER) :
currency = fields.Many2One('currency.currency', 'Currency',
states={
'required': Bool(Eval('unit_price')),
},
depends=['unit_price'])
...
@fields.depends('_parent_HEADER.currency','HEADER')
def on_change_with_currency(self):
currency = self.HEADER.currency if self.HEADER else None
if currency:
return
currency.idCurrency on the HEADER doesn't need to be displayed, so this field is not in the xml form view.
When i try to create a new LINE with a new HEADER, i got this error : 'header' Model has no attribute currency
If i had the currency field in the xml form view of the HEADER (visible or not) , there is no error...
Why ?
Hope my explanations are understandable :-)