> If the string is clear for the user then it should be also clear for the
> developer.
> It is a very *important* rule in Tryton design. The name of the field
> must be linked to the string. And there is no reason for which it can be
> break.
> And how do you know that the field you are using is a Many2One or a
> xxx2Many. Believe me, this is the worst choice you could do. In 1 month,
> when you will need to fix something, you will be completly lost.
>
ok, i was not sure myself about the only-singular rule, I bow to the
Master and banish it from now on!
> > I also use snippets on Gedit to speed up and automate code writing and
> > this also drives me in the direction of name semplification.
>
> This is really a wrong choice because you don't put semantic in your
> field name. And this semantic is like a documentation of your code.
no, no, the GEdit snippet mechanism lets you mix fixed text and
'variables' to be filled at use time. For example:
<label name="${1}"/>
<field name="${1}"/>
and you'll be prompted for the $1 value that will be placed in both $1
positions at once. So semantic CAN be rispected because you can name
objects, it's just a matter of tuning the snippet code, that's of course
simplier if you use the same variable in more places
Back to the heart of the matter:
> >
> > class Edition():
> > Project = Many2One('Project')
>
> companies = fields.Function(fields.One2Many('company.company', None,
> 'Companies'))
>
> > Office = Many2One('Office',
>
> domain=[('Company', 'in', Eval('companies', []))]
> >
> You must create a function fields that gives you the companies liked to
> the project and then you can use this fields to construct a domain.
>
ok, it sounds perfectly logical. I created the function field and added
a getter function (in the previous examples i simplified models/fields
names for shortness' sake, from now on i'll keep them as in source
code):
.........................................................................
class Edition(ModelSQL, ModelView):
.....
PlanCompanies = fields.Function(
fields.One2Many('train.Company', None,'Companies'),
'get_plan_companies')
CompanyOffice = fields.Many2One(
'train.CompanyOffice',
string='Company Office',
domain=[('Company','in',Eval('PlanCompanies'))])
.....
def get_plan_companies(self, ids, name):
if not ids:
return []
res = {}
for Edition in self.browse(ids):
Project = Edition.Project
TrainingPlan = Project.TrainingPlan
Companies = TrainingPlan.Company
for Company in Companies:
res[Company.id] = Company.name
print res
return res
.........................................................................
the get_plan_companies() function in itself works but:
- i'm not sure if the res dictionary is filled correctly
- it seems to be called (i used some print to debug) ONLY if there is a
PlanCompanies field into the Edition form (that is not needed and messes
up the form). Otherwise the CompanyOffice selection list is empty.
I'm still missing some (many...) key point of the tryton logic.
thanks, leo
--
vuk di Leonardo Venturini
web developement
via Zandonai, 1 - 24129 Bergamo (BG)
Italy
P.IVA 03084840168
cell 339.6132096
http://vuk.bg.it
--
[email protected] mailing list