[FIX] analytic: only show plans from the company

Before this fix, user could include accounts in the widget from another company than the object's one when in multi-company mode.
It could cause problems with validation too.

Now we take the company of the object when getting the plans (or the current company if no object's company).

t-3040926

closes odoo/odoo#104150

X-original-commit: 21d754ddafee653d9958443accda2de747caed53
Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
This commit is contained in:
gawa-odoo
2022-10-26 14:05:59 +02:00
parent a0f4957304
commit c3eb3021c1
3 changed files with 8 additions and 2 deletions
+2 -1
View File
@@ -2347,7 +2347,8 @@ class AccountMoveLine(models.Model):
'account': line.account_id.id,
'business_domain': line.move_id.move_type in ['out_invoice', 'out_refund', 'out_receipt'] and 'invoice'
or line.move_id.move_type in ['in_invoice', 'in_refund', 'in_receipt'] and 'bill'
or 'general'
or 'general',
'company_id': self.company_id.id,
}) if plan['applicability'] == 'mandatory']
if not mandatory_plans_ids:
continue
+3 -1
View File
@@ -134,7 +134,9 @@ class AccountAnalyticPlan(models.Model):
This list is computed based on the applicabilities of root plans. """
list_plans = []
set_plan_ids = {}
all_plans = self.search([('parent_id', '=', False), '|', ('account_ids', '!=', False), ('children_ids.account_ids', '!=', False)])
company_id = kwargs.get('company_id', self.env.company.id)
all_plans = self.search([('parent_id', '=', False), '|', ('account_ids', '!=', False), ('children_ids.account_ids', '!=', False),
'|', ('company_id', '=', company_id), ('company_id', '=', False)])
for plan in all_plans:
applicability = plan._get_applicability(**kwargs)
if applicability != 'unavailable':
@@ -154,6 +154,9 @@ export class AnalyticDistribution extends Component {
if (existing_account_ids.length) {
args['existing_account_ids'] = existing_account_ids;
}
if (this.props.record.data.company_id) {
args['company_id'] = this.props.record.data.company_id[0];
}
return args;
}