Skip to content
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

Closed

Conversation

ernestotejeda
Copy link
Member

@ernestotejeda ernestotejeda commented Jan 9, 2019

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

@pedrobaeza
Copy link
Member

@sbidoul this is needed for #148

@pedrobaeza pedrobaeza mentioned this pull request Jan 9, 2019
1 task
@sbidoul
Copy link
Member

sbidoul commented Jan 9, 2019

Interesting. I'll look into it within a couple of weeks.

@sbidoul sbidoul changed the title 11.0 imp account_id mis_builder Configurable account.account model (can use any model that has a code field) Jan 13, 2019

aep = self.report_id._prepare_aep(self.query_company_ids,
self.currency_id,
account_model=account_model)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@sbidoul sbidoul Jan 13, 2019

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

Copy link
Member

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.

Copy link
Member

@sbidoul sbidoul left a 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.

@pedrobaeza
Copy link
Member

@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.

@sbidoul
Copy link
Member

sbidoul commented Jan 14, 2019

@pedrobaeza yes, correct, I meant the template.

@pedrobaeza
Copy link
Member

Well, that can an option, but why complicate it when it can be auto-inferred? I don't get the advantage.

@sbidoul
Copy link
Member

sbidoul commented Jan 14, 2019

@pedrobaeza I don't understand your last comment.

@pedrobaeza
Copy link
Member

As we have the model of account_id field, we already know it, so why re-define it on template level?

@sbidoul
Copy link
Member

sbidoul commented Jan 14, 2019

That's not what I suggest in #149 (comment)

What I suggest is

  • add a field named "Actuals move lines model" on mis.report (default = acccount.move.line)
  • from that, the account_id model can be found
  • in mis.report.instance.period configuration, enforce the account_id field used for the "Actuals (alternative)" models uses the same account_id model as the main one

@pedrobaeza
Copy link
Member

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...

@sbidoul
Copy link
Member

sbidoul commented Jan 14, 2019

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.

@pedrobaeza
Copy link
Member

@ernestotejeda can you do the requested changes or is there something you don't understand?

@ernestotejeda
Copy link
Member Author

Yes @pedrobaeza, I can try to do the requested changes according to #149 (comment). I agree with @sbidoul, thanks.

@ernestotejeda ernestotejeda force-pushed the 11.0-imp-account_id-mis_builder branch 2 times, most recently from f1aa2ab to 4688386 Compare January 16, 2019 15:37
@ernestotejeda
Copy link
Member Author

@sbidoul i have done the changes proposed

@rafaelbn
Copy link
Member

Hi @ernestotejeda This branch has conflicts that must be resolved, could you rebase?

@sbidoul could you give a feedback of the last changes?

Copy link
Member

@sbidoul sbidoul left a 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.

# Account model
self._account_model = account_model
if account_model is None:
self._account_model = self.env['account.account']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with_context(active_test=False).\

self._account_model = env['account.account']
self._account_model = account_model
if account_model is None:
self._account_model = env['account.account']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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',
)
Copy link
Member

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

@@ -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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kpi_matrix = KpiMatrix(self.env, self.env[self.account_model.model])
kpi_matrix = KpiMatrix(self.env, self.account_model)

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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Member

@sbidoul sbidoul Aug 16, 2019

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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.env[self.report_id.account_model.model])
self.report_id.account_model)

))
self.report._compute_account_model()
Copy link
Member

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.

@@ -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')]"/>
Copy link
Member

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.

@rafaelbn
Copy link
Member

Hi @ernestotejeda please rebase, @pedrobaeza @sbidoul could we discuss this?

#148 depends on this

Thanks

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
@ernestotejeda
Copy link
Member Author

@rafaelbn, @sbidoul , @pedrobaeza I have done the changes proposed by @sbidoul

@sbidoul
Copy link
Member

sbidoul commented Oct 11, 2019

Thanks, I'll review soon.

@sbidoul
Copy link
Member

sbidoul commented Oct 17, 2019

@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.

@sbidoul
Copy link
Member

sbidoul commented Oct 18, 2019

Closing as it is included in 10.0-staging and will be soon merged in 11.0. Shout if you see any issue.

@sbidoul sbidoul closed this Oct 18, 2019
@pedrobaeza pedrobaeza deleted the 11.0-imp-account_id-mis_builder branch October 27, 2019 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants