-
-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable account.account model (can use any model that has a code field) #149
Conversation
Interesting. I'll look into it within a couple of weeks. |
|
||
aep = self.report_id._prepare_aep(self.query_company_ids, | ||
self.currency_id, | ||
account_model=account_model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this in more details, I think it does not make sense to have a different account_model for different columns, because of account details expansion which would become meaningless if different account objects are used in different columns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOW, this may work, but the account model must be configured globally at the level of mis.report, and passed to the AEP constructor, as well as to the KPI matrix constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, better, define the AML model used for Actuals at the mis.report level, and make sure Actual (alternative) models used in columns have the same account model in the account_id m2o.
updated: mis.report instead of mis.report.instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to say it is that one way or another, the same AEP must be used for all columns and the account model must therefore be known before the for period
loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This require more thinking.
@sbidoul are you saying that each time you want to create an instance, you have to define all of these things? I think all this information should be in the template, not the instance. |
@pedrobaeza yes, correct, I meant the template. |
Well, that can an option, but why complicate it when it can be auto-inferred? I don't get the advantage. |
@pedrobaeza I don't understand your last comment. |
As we have the model of |
That's not what I suggest in #149 (comment) What I suggest is
|
But this is what I'm saying that is not really needed, as you already know the m2o model from the model definition. Why do you need to enforce that thing? It would make sense if you enforce all things, like using a template with an specific actual data, but only for the model... Other thing that I don't understand is that the data source is specified at instance level instead of template. Maybe a template can work with several data sources, but this should be specified by a m2m, but not having to be configured each time for each report... |
The data source is specified at the column level in the instance. There are no columns in the template. This allows having a column for actuals, another for committed, and a third for budget for example. I'm just saying that we must enforce the same account model is used for the data sources used in all columns. This is necessary because when you expand accounts they are displayed in rows and the rows must make sense for all columns. |
@ernestotejeda can you do the requested changes or is there something you don't understand? |
Yes @pedrobaeza, I can try to do the requested changes according to #149 (comment). I agree with @sbidoul, thanks. |
f1aa2ab
to
4688386
Compare
@sbidoul i have done the changes proposed |
Hi @ernestotejeda This branch has conflicts that must be resolved, could you rebase? @sbidoul could you give a feedback of the last changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ernestotejeda @rafaelbn This is going into the right direction. I made a few relatively minor comments.
Could you make this PR to 10.0? I'll then forward port quickly as soon as it is merged.
Also could you add a file named readme/newsfragments/<pr or issue number>.feature
that provides a short description of the feature that will be included automatically in the changelog?
Thanks for this work.
mis_builder/models/aep.py
Outdated
# Account model | ||
self._account_model = account_model | ||
if account_model is None: | ||
self._account_model = self.env['account.account'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._account_model = self.env['account.account'] | |
self._account_model = self.env[account_model or 'account.account'].with_context(active_test=False) |
for key, acc_domains in self._map_account_ids.items(): | ||
all_account_ids = set() | ||
for acc_domain in acc_domains: | ||
acc_domain_with_company = expression.AND([ | ||
acc_domain, | ||
[('company_id', 'in', self.companies.ids)], | ||
]) | ||
account_ids = account_model.\ | ||
account_ids = self._account_model.\ | ||
with_context(active_test=False).\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_context(active_test=False).\ |
mis_builder/models/kpimatrix.py
Outdated
self._account_model = env['account.account'] | ||
self._account_model = account_model | ||
if account_model is None: | ||
self._account_model = env['account.account'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._account_model = env['account.account'] | |
self._account_model = env[account_model or 'account.account'] |
compute='_compute_account_model', | ||
comodel_name='ir.model', | ||
string='Account model', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this field a Char
mis_builder/models/mis_report.py
Outdated
@@ -520,15 +551,15 @@ def copy(self, default=None): | |||
@api.multi | |||
def prepare_kpi_matrix(self): | |||
self.ensure_one() | |||
kpi_matrix = KpiMatrix(self.env) | |||
kpi_matrix = KpiMatrix(self.env, self.env[self.account_model.model]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kpi_matrix = KpiMatrix(self.env, self.env[self.account_model.model]) | |
kpi_matrix = KpiMatrix(self.env, self.account_model) |
mis_builder/models/mis_report.py
Outdated
for kpi in self.kpi_ids: | ||
kpi_matrix.declare_kpi(kpi) | ||
return kpi_matrix | ||
|
||
@api.multi | ||
def _prepare_aep(self, companies, currency=None): | ||
self.ensure_one() | ||
aep = AEP(companies, currency) | ||
aep = AEP(companies, currency, self.env[self.account_model.model]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aep = AEP(companies, currency, self.env[self.account_model.model]) | |
aep = AEP(companies, currency, self.account_model) |
record_model = record.source_aml_model_id.field_id.filtered( | ||
lambda r: r.name == 'account_id').relation | ||
period_model = record.report_id.account_model.model | ||
if record_model != period_model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/period_model/report_account_model/
s/record_model/period_account_model/
@@ -703,7 +718,8 @@ def drilldown(self, arg): | |||
account_id = arg.get('account_id') | |||
if period_id and expr and AEP.has_account_var(expr): | |||
period = self.env['mis.report.instance.period'].browse(period_id) | |||
aep = AEP(self.query_company_ids, self.currency_id) | |||
aep = AEP(self.query_company_ids, self.currency_id, | |||
self.env[self.report_id.account_model.model]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.env[self.report_id.account_model.model]) | |
self.report_id.account_model) |
)) | ||
self.report._compute_account_model() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be necessary to change the test since move_lines_source
has a default value.
mis_builder_demo/data/mis_report.xml
Outdated
@@ -6,6 +6,8 @@ | |||
<record id="mis_report_expenses" model="mis.report"> | |||
<field name="name">Demo Expenses</field> | |||
<field name="style_id" ref="mis_report_expenses_style1"/> | |||
<field name="move_lines_source" search="[('model', '=', 'account.move.line')]"/> | |||
<field name="account_model" search="[('model', '=', 'account.account')]"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary since there is a default value.
Hi @ernestotejeda please rebase, @pedrobaeza @sbidoul could we discuss this? #148 depends on this Thanks |
4688386
to
eb16300
Compare
The account_id field of the model selected in 'Move lines source' in the Period form (mis.report.instance.period) can be a Many2one relationship with any class that has the field code
eb16300
to
344c4cc
Compare
@rafaelbn, @sbidoul , @pedrobaeza I have done the changes proposed by @sbidoul |
Thanks, I'll review soon. |
@ernestotejeda I ported your commit to 10.0 and slightly amended it to resolve the conflict that was due to #242. It is in #240 (ce73613). Would you like to have quick look at it? I removed the changes to the test, because the change should be fully backward compatible. I also changed the way you added contributors, to conserve the style of adding contributors chronologically, I hope you don't mind. |
Closing as it is included in 10.0-staging and will be soon merged in 11.0. Shout if you see any issue. |
The account_id field of the model selected in 'Move lines source'
in the Period form (mis.report.instance.period) can be a Many2one
relationship with any class that has the field code
Cc @Tecnativa
TT14942