mirror of
https://github.com/bringout/oca-ocb-project.git
synced 2026-04-21 15:42:06 +02:00
19.0 vanilla
This commit is contained in:
parent
a2f74aefd8
commit
4a4d12c333
844 changed files with 212348 additions and 270090 deletions
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from . import project
|
||||
from . import project_project
|
||||
from . import purchase_order_line
|
||||
from . import purchase_order
|
||||
|
|
|
|||
|
|
@ -1,212 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
|
||||
from odoo import api, fields, models, _, _lt
|
||||
from odoo.osv import expression
|
||||
|
||||
from datetime import date
|
||||
|
||||
class Project(models.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
purchase_orders_count = fields.Integer('# Purchase Orders', compute='_compute_purchase_orders_count', groups='purchase.group_purchase_user')
|
||||
|
||||
@api.depends('analytic_account_id')
|
||||
def _compute_purchase_orders_count(self):
|
||||
if not self.analytic_account_id:
|
||||
self.purchase_orders_count = 0
|
||||
return
|
||||
query = self.env['purchase.order.line']._search([])
|
||||
query.add_where('purchase_order_line.analytic_distribution ?| %s', [[str(account_id) for account_id in self.analytic_account_id.ids]])
|
||||
|
||||
query.order = None
|
||||
query_string, query_param = query.select(
|
||||
'jsonb_object_keys(purchase_order_line.analytic_distribution) as account_id',
|
||||
'COUNT(DISTINCT(order_id)) as purchase_order_count',
|
||||
)
|
||||
query_string = f"{query_string} GROUP BY jsonb_object_keys(purchase_order_line.analytic_distribution)"
|
||||
|
||||
self._cr.execute(query_string, query_param)
|
||||
data = {int(record.get('account_id')): record.get('purchase_order_count') for record in self._cr.dictfetchall()}
|
||||
for project in self:
|
||||
project.purchase_orders_count = data.get(project.analytic_account_id.id, 0)
|
||||
|
||||
# ----------------------------
|
||||
# Actions
|
||||
# ----------------------------
|
||||
|
||||
def action_open_project_purchase_orders(self):
|
||||
query = self.env['purchase.order.line']._search([])
|
||||
query.add_where('purchase_order_line.analytic_distribution ? %s', [str(self.analytic_account_id.id)])
|
||||
query_string, query_param = query.select('order_id')
|
||||
self._cr.execute(query_string, query_param)
|
||||
purchase_order_ids = [pol.get('order_id') for pol in self._cr.dictfetchall()]
|
||||
action_window = {
|
||||
'name': _('Purchase Orders'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.order',
|
||||
'views': [[False, 'tree'], [False, 'form']],
|
||||
'domain': [('id', 'in', purchase_order_ids)],
|
||||
'context': {
|
||||
'project_id': self.id,
|
||||
}
|
||||
}
|
||||
if len(purchase_order_ids) == 1:
|
||||
action_window['views'] = [[False, 'form']]
|
||||
action_window['res_id'] = purchase_order_ids[0]
|
||||
return action_window
|
||||
|
||||
def action_profitability_items(self, section_name, domain=None, res_id=False):
|
||||
if section_name == 'purchase_order':
|
||||
action = {
|
||||
'name': _('Purchase Order Items'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.order.line',
|
||||
'views': [[False, 'tree'], [False, 'form']],
|
||||
'domain': domain,
|
||||
'context': {
|
||||
'create': False,
|
||||
'edit': False,
|
||||
},
|
||||
}
|
||||
if res_id:
|
||||
action['res_id'] = res_id
|
||||
if 'views' in action:
|
||||
action['views'] = [
|
||||
(view_id, view_type)
|
||||
for view_id, view_type in action['views']
|
||||
if view_type == 'form'
|
||||
] or [False, 'form']
|
||||
action['view_mode'] = 'form'
|
||||
return action
|
||||
return super().action_profitability_items(section_name, domain, res_id)
|
||||
|
||||
# ----------------------------
|
||||
# Project Updates
|
||||
# ----------------------------
|
||||
|
||||
def _get_stat_buttons(self):
|
||||
buttons = super(Project, self)._get_stat_buttons()
|
||||
if self.user_has_groups('purchase.group_purchase_user'):
|
||||
buttons.append({
|
||||
'icon': 'credit-card',
|
||||
'text': _lt('Purchase Orders'),
|
||||
'number': self.purchase_orders_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_open_project_purchase_orders',
|
||||
'show': self.purchase_orders_count > 0,
|
||||
'sequence': 36,
|
||||
})
|
||||
return buttons
|
||||
|
||||
def _get_profitability_aal_domain(self):
|
||||
return expression.AND([
|
||||
super()._get_profitability_aal_domain(),
|
||||
['|', ('move_line_id', '=', False), ('move_line_id.purchase_line_id', '=', False)],
|
||||
])
|
||||
|
||||
def _get_profitability_labels(self):
|
||||
labels = super()._get_profitability_labels()
|
||||
labels['purchase_order'] = _lt('Purchase Orders')
|
||||
labels['other_purchase_costs'] = _lt('Other Costs')
|
||||
return labels
|
||||
|
||||
def _get_profitability_sequence_per_invoice_type(self):
|
||||
sequence_per_invoice_type = super()._get_profitability_sequence_per_invoice_type()
|
||||
sequence_per_invoice_type['purchase_order'] = 9
|
||||
sequence_per_invoice_type['other_purchase_costs'] = 10
|
||||
return sequence_per_invoice_type
|
||||
|
||||
def _get_profitability_items(self, with_action=True):
|
||||
profitability_items = super()._get_profitability_items(with_action)
|
||||
if self.analytic_account_id:
|
||||
query = self.env['purchase.order.line'].sudo()._search([
|
||||
('state', 'in', ['purchase', 'done']),
|
||||
'|',
|
||||
('qty_invoiced', '>', 0),
|
||||
'|', ('qty_to_invoice', '>', 0), ('product_qty', '>', 0),
|
||||
])
|
||||
query.add_where('purchase_order_line.analytic_distribution ? %s', [str(self.analytic_account_id.id)])
|
||||
query_string, query_param = query.select('"purchase_order_line".id', 'qty_invoiced', 'qty_to_invoice', 'product_qty', 'price_subtotal', 'purchase_order_line.currency_id', '"purchase_order_line".analytic_distribution')
|
||||
self._cr.execute(query_string, query_param)
|
||||
purchase_order_line_read = [{
|
||||
**pol,
|
||||
'invoice_lines': self.env['purchase.order.line'].browse(pol['id']).sudo().invoice_lines, # One2Many cannot be queried, they are not columns
|
||||
} for pol in self._cr.dictfetchall()]
|
||||
purchase_order_line_invoice_line_ids = self._get_already_included_profitability_invoice_line_ids()
|
||||
if purchase_order_line_read:
|
||||
|
||||
# Get conversion rate from currencies to currency of the project
|
||||
currency_ids = {pol['currency_id'] for pol in purchase_order_line_read + [{'currency_id': self.currency_id.id}]}
|
||||
rates = self.env['res.currency'].browse(list(currency_ids))._get_rates(self.company_id, date.today())
|
||||
conversion_rates = {cid: rates[self.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
|
||||
amount_invoiced = amount_to_invoice = 0.0
|
||||
purchase_order_line_ids = []
|
||||
for pol_read in purchase_order_line_read:
|
||||
purchase_order_line_invoice_line_ids.extend(pol_read['invoice_lines'].ids)
|
||||
price_subtotal = self.currency_id.round(pol_read['price_subtotal'] * conversion_rates[pol_read['currency_id']])
|
||||
price_subtotal_unit = price_subtotal / pol_read['product_qty'] if pol_read['product_qty'] else 0.0
|
||||
analytic_contribution = pol_read['analytic_distribution'][str(self.analytic_account_id.id)] / 100.
|
||||
amount_invoiced -= price_subtotal_unit * pol_read['qty_invoiced'] * analytic_contribution if pol_read['qty_invoiced'] > 0 else 0.0
|
||||
if pol_read['qty_to_invoice'] > 0:
|
||||
amount_to_invoice -= price_subtotal_unit * pol_read['qty_to_invoice'] * analytic_contribution
|
||||
else:
|
||||
amount_to_invoice -= price_subtotal_unit * (pol_read['product_qty'] - pol_read['qty_invoiced']) * analytic_contribution
|
||||
purchase_order_line_ids.append(pol_read['id'])
|
||||
costs = profitability_items['costs']
|
||||
section_id = 'purchase_order'
|
||||
purchase_order_costs = {'id': section_id, 'sequence': self._get_profitability_sequence_per_invoice_type()[section_id], 'billed': amount_invoiced, 'to_bill': amount_to_invoice}
|
||||
if with_action and purchase_order_line_ids and self.user_has_groups('purchase.group_purchase_user'):
|
||||
args = [section_id, [('id', 'in', purchase_order_line_ids)]]
|
||||
if len(purchase_order_line_ids) == 1:
|
||||
args.append(purchase_order_line_ids[0])
|
||||
action = {'name': 'action_profitability_items', 'type': 'object', 'args': json.dumps(args)}
|
||||
purchase_order_costs['action'] = action
|
||||
costs['data'].append(purchase_order_costs)
|
||||
costs['total']['billed'] += amount_invoiced
|
||||
costs['total']['to_bill'] += amount_to_invoice
|
||||
# calculate the cost of bills without a purchase order
|
||||
query = self.env['account.move.line'].sudo()._search([
|
||||
('move_id.move_type', 'in', ['in_invoice', 'in_refund']),
|
||||
('parent_state', 'in', ['draft', 'posted']),
|
||||
('id', 'not in', purchase_order_line_invoice_line_ids),
|
||||
])
|
||||
query.add_where('account_move_line.analytic_distribution ? %s', [str(self.analytic_account_id.id)])
|
||||
# account_move_line__move_id is the alias of the joined table account_move in the query
|
||||
# we can use it, because of the "move_id.move_type" clause in the domain of the query, which generates the join
|
||||
# this is faster than a search_read followed by a browse on the move_id to retrieve the move_type of each account.move.line
|
||||
query_string, query_param = query.select('balance', 'parent_state', 'account_move_line.company_currency_id', 'account_move_line.analytic_distribution', 'account_move_line__move_id.move_type')
|
||||
self._cr.execute(query_string, query_param)
|
||||
bills_move_line_read = self._cr.dictfetchall()
|
||||
if bills_move_line_read:
|
||||
|
||||
# Get conversion rate from currencies to currency of the project
|
||||
currency_ids = {bml['company_currency_id'] for bml in bills_move_line_read + [{'company_currency_id': self.currency_id.id}]}
|
||||
rates = self.env['res.currency'].browse(list(currency_ids))._get_rates(self.company_id, date.today())
|
||||
conversion_rates = {cid: rates[self.currency_id.id] / rate_from for cid, rate_from in rates.items()}
|
||||
|
||||
amount_invoiced = amount_to_invoice = 0.0
|
||||
for moves_read in bills_move_line_read:
|
||||
line_balance = self.currency_id.round(moves_read['balance'] * conversion_rates[moves_read['company_currency_id']])
|
||||
analytic_contribution = moves_read['analytic_distribution'][str(self.analytic_account_id.id)] / 100.
|
||||
if moves_read['parent_state'] == 'draft':
|
||||
amount_to_invoice -= line_balance * analytic_contribution
|
||||
else: # moves_read['parent_state'] == 'posted'
|
||||
amount_invoiced -= line_balance * analytic_contribution
|
||||
# don't display the section if the final values are both 0 (bill -> vendor credit)
|
||||
if amount_invoiced != 0 or amount_to_invoice != 0:
|
||||
costs = profitability_items['costs']
|
||||
section_id = 'other_purchase_costs'
|
||||
bills_costs = {
|
||||
'id': section_id,
|
||||
'sequence': self._get_profitability_sequence_per_invoice_type()[section_id],
|
||||
'billed': amount_invoiced,
|
||||
'to_bill': amount_to_invoice,
|
||||
}
|
||||
costs['data'].append(bills_costs)
|
||||
costs['total']['billed'] += amount_invoiced
|
||||
costs['total']['to_bill'] += amount_to_invoice
|
||||
return profitability_items
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
|
||||
from odoo import fields, models, _
|
||||
from odoo.fields import Domain
|
||||
|
||||
|
||||
class ProjectProject(models.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
purchase_orders_count = fields.Integer('# Purchase Orders', compute='_compute_purchase_orders_count', groups='purchase.group_purchase_user', export_string_translation=False)
|
||||
|
||||
def _compute_purchase_orders_count(self):
|
||||
purchase_orders_per_project = dict(
|
||||
self.env['purchase.order']._read_group(
|
||||
domain=[
|
||||
('project_id', 'in', self.ids),
|
||||
('order_line', '!=', False),
|
||||
],
|
||||
groupby=['project_id'],
|
||||
aggregates=['id:array_agg'],
|
||||
)
|
||||
)
|
||||
purchase_orders_count_per_project_from_lines = dict(
|
||||
self.env['purchase.order.line']._read_group(
|
||||
domain=[
|
||||
('order_id', 'not in', [order_id for values in purchase_orders_per_project.values() for order_id in values]),
|
||||
('analytic_distribution', 'in', self.account_id.ids),
|
||||
],
|
||||
groupby=['analytic_distribution'],
|
||||
aggregates=['__count'],
|
||||
)
|
||||
)
|
||||
|
||||
projects_no_account = self.filtered(lambda project: not project.account_id)
|
||||
for project in projects_no_account:
|
||||
project.purchase_orders_count = len(purchase_orders_per_project.get(project, []))
|
||||
|
||||
purchase_orders_per_project = {project.account_id.id: len(orders) for project, orders in purchase_orders_per_project.items()}
|
||||
for project in (self - projects_no_account):
|
||||
project.purchase_orders_count = purchase_orders_per_project.get(project.account_id.id, 0) + purchase_orders_count_per_project_from_lines.get(project.account_id.id, 0)
|
||||
|
||||
# ----------------------------
|
||||
# Actions
|
||||
# ----------------------------
|
||||
|
||||
def action_open_project_purchase_orders(self):
|
||||
purchase_orders = self.env['purchase.order.line'].search([
|
||||
'|',
|
||||
('analytic_distribution', 'in', self.account_id.ids),
|
||||
('order_id.project_id', '=', self.id),
|
||||
]).order_id
|
||||
action_window = {
|
||||
'name': self.env._('Purchase Orders'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.order',
|
||||
'views': [
|
||||
[False, 'list'], [self.env.ref('purchase.purchase_order_view_kanban_without_dashboard').id, 'kanban'],
|
||||
[False, 'form'], [False, 'calendar'], [False, 'pivot'], [False, 'graph'], [False, 'activity'],
|
||||
],
|
||||
'domain': [('id', 'in', purchase_orders.ids)],
|
||||
'context': {
|
||||
'default_project_id': self.id,
|
||||
},
|
||||
'help': "<p class='o_view_nocontent_smiling_face'>%s</p><p>%s</p>" % (
|
||||
_("No purchase order found. Let's create one."),
|
||||
_("Once you ordered your products from your supplier, confirm your request for quotation and it will turn "
|
||||
"into a purchase order."),
|
||||
),
|
||||
}
|
||||
if len(purchase_orders) == 1 and not self.env.context.get('from_embedded_action'):
|
||||
action_window['views'] = [[False, 'form']]
|
||||
action_window['res_id'] = purchase_orders.id
|
||||
return action_window
|
||||
|
||||
def action_profitability_items(self, section_name, domain=None, res_id=False):
|
||||
if section_name == 'purchase_order':
|
||||
action = {
|
||||
'name': self.env._('Purchase Orders'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.order',
|
||||
'views': [[False, 'list'], [False, 'form']],
|
||||
'domain': domain,
|
||||
'context': {
|
||||
'create': False,
|
||||
'edit': False,
|
||||
},
|
||||
}
|
||||
if res_id:
|
||||
action['res_id'] = res_id
|
||||
if 'views' in action:
|
||||
action['views'] = [
|
||||
(view_id, view_type)
|
||||
for view_id, view_type in action['views']
|
||||
if view_type == 'form'
|
||||
] or [False, 'form']
|
||||
action['view_mode'] = 'form'
|
||||
return action
|
||||
return super().action_profitability_items(section_name, domain, res_id)
|
||||
|
||||
# ----------------------------
|
||||
# Project Updates
|
||||
# ----------------------------
|
||||
|
||||
def _get_stat_buttons(self):
|
||||
buttons = super()._get_stat_buttons()
|
||||
if self.env.user.has_group('purchase.group_purchase_user'):
|
||||
buttons.append({
|
||||
'icon': 'credit-card',
|
||||
'text': self.env._('Purchase Orders'),
|
||||
'number': self.purchase_orders_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_open_project_purchase_orders',
|
||||
'show': self.purchase_orders_count > 0,
|
||||
'sequence': 36,
|
||||
})
|
||||
return buttons
|
||||
|
||||
def _get_profitability_aal_domain(self):
|
||||
return Domain.AND([
|
||||
super()._get_profitability_aal_domain(),
|
||||
['|', ('move_line_id', '=', False), ('move_line_id.purchase_line_id', '=', False)],
|
||||
])
|
||||
|
||||
def _add_purchase_items(self, profitability_items, with_action=True):
|
||||
return False
|
||||
|
||||
def _get_profitability_labels(self):
|
||||
labels = super()._get_profitability_labels()
|
||||
labels['purchase_order'] = self.env._('Purchase Orders')
|
||||
return labels
|
||||
|
||||
def _get_profitability_sequence_per_invoice_type(self):
|
||||
sequence_per_invoice_type = super()._get_profitability_sequence_per_invoice_type()
|
||||
sequence_per_invoice_type['purchase_order'] = 10
|
||||
return sequence_per_invoice_type
|
||||
|
||||
def _get_profitability_items(self, with_action=True):
|
||||
profitability_items = super()._get_profitability_items(with_action)
|
||||
if self.account_id:
|
||||
purchase_lines = self.env['purchase.order.line'].sudo().search([
|
||||
('analytic_distribution', 'in', self.account_id.ids),
|
||||
('state', 'in', 'purchase')
|
||||
])
|
||||
purchase_order_line_invoice_line_ids = self._get_already_included_profitability_invoice_line_ids()
|
||||
with_action = with_action and (
|
||||
self.env.user.has_group('purchase.group_purchase_user')
|
||||
or self.env.user.has_group('account.group_account_invoice')
|
||||
or self.env.user.has_group('account.group_account_readonly')
|
||||
)
|
||||
if purchase_lines:
|
||||
amount_invoiced = amount_to_invoice = 0.0
|
||||
purchase_order_line_invoice_line_ids.extend(purchase_lines.invoice_lines.ids)
|
||||
for purchase_line in purchase_lines:
|
||||
price_subtotal = purchase_line.currency_id._convert(purchase_line.price_subtotal, self.currency_id, self.company_id)
|
||||
# an analytic account can appear several time in an analytic distribution with different repartition percentage
|
||||
analytic_contribution = sum(
|
||||
percentage for ids, percentage in purchase_line.analytic_distribution.items()
|
||||
if str(self.account_id.id) in ids.split(',')
|
||||
) / 100.
|
||||
purchase_line_amount_to_invoice = price_subtotal * analytic_contribution
|
||||
invoice_lines = purchase_line.invoice_lines.filtered(
|
||||
lambda l:
|
||||
l.parent_state != 'cancel'
|
||||
and l.analytic_distribution
|
||||
and any(
|
||||
str(self.account_id.id) in key.split(',')
|
||||
for key in l.analytic_distribution
|
||||
)
|
||||
)
|
||||
if invoice_lines:
|
||||
invoiced_qty = sum(invoice_lines.filtered(lambda l: not l.is_refund).mapped('quantity'))
|
||||
if invoiced_qty < purchase_line.product_qty:
|
||||
amount_to_invoice -= purchase_line_amount_to_invoice * ((purchase_line.product_qty - invoiced_qty) / purchase_line.product_qty)
|
||||
for line in invoice_lines:
|
||||
price_subtotal = line.currency_id._convert(line.price_subtotal, self.currency_id, self.company_id)
|
||||
if not line.analytic_distribution:
|
||||
continue
|
||||
# an analytic account can appear several time in an analytic distribution with different repartition percentage
|
||||
analytic_contribution = sum(
|
||||
percentage for ids, percentage in line.analytic_distribution.items()
|
||||
if str(self.account_id.id) in ids.split(',')
|
||||
) / 100.
|
||||
cost = price_subtotal * analytic_contribution * (-1 if line.is_refund else 1)
|
||||
if line.parent_state == 'posted':
|
||||
amount_invoiced -= cost
|
||||
else:
|
||||
amount_to_invoice -= cost
|
||||
else:
|
||||
amount_to_invoice -= purchase_line_amount_to_invoice
|
||||
|
||||
costs = profitability_items['costs']
|
||||
section_id = 'purchase_order'
|
||||
purchase_order_costs = {'id': section_id, 'sequence': self._get_profitability_sequence_per_invoice_type()[section_id], 'billed': amount_invoiced, 'to_bill': amount_to_invoice}
|
||||
if with_action:
|
||||
purchase_order = purchase_lines.order_id
|
||||
args = [section_id, [('id', 'in', purchase_order.ids)]]
|
||||
if len(purchase_order) == 1:
|
||||
args.append(purchase_order.id)
|
||||
action = {'name': 'action_profitability_items', 'type': 'object', 'args': json.dumps(args)}
|
||||
purchase_order_costs['action'] = action
|
||||
costs['data'].append(purchase_order_costs)
|
||||
costs['total']['billed'] += amount_invoiced
|
||||
costs['total']['to_bill'] += amount_to_invoice
|
||||
domain = [
|
||||
('move_id.move_type', 'in', ['in_invoice', 'in_refund']),
|
||||
('parent_state', 'in', ['draft', 'posted']),
|
||||
('price_subtotal', '!=', 0),
|
||||
('id', 'not in', purchase_order_line_invoice_line_ids),
|
||||
]
|
||||
self._get_costs_items_from_purchase(domain, profitability_items, with_action=with_action)
|
||||
return profitability_items
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = 'purchase.order'
|
||||
|
||||
project_id = fields.Many2one('project.project', domain=[('is_template', '=', False)])
|
||||
|
|
@ -1,14 +1,36 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = 'purchase.order.line'
|
||||
|
||||
@api.depends('product_id', 'order_id.partner_id', 'order_id.project_id')
|
||||
def _compute_analytic_distribution(self):
|
||||
super()._compute_analytic_distribution()
|
||||
for line in self:
|
||||
if line._context.get('project_id'):
|
||||
line.analytic_distribution = {line.env['project.project'].browse(line._context['project_id']).analytic_account_id.id: 100}
|
||||
ctx_project = self.env['project.project'].browse(self.env.context.get('project_id'))
|
||||
project_lines = self.filtered(lambda l: not l.display_type and (ctx_project or l.order_id.project_id))
|
||||
empty_project_lines = project_lines.filtered(lambda l: not l.analytic_distribution)
|
||||
super(PurchaseOrderLine, (self - project_lines) + empty_project_lines)._compute_analytic_distribution()
|
||||
|
||||
for line in project_lines:
|
||||
project = ctx_project or line.order_id.project_id
|
||||
if line.analytic_distribution:
|
||||
applied_root_plans = self.env['account.analytic.account'].browse(
|
||||
list({int(account_id) for ids in line.analytic_distribution for account_id in ids.split(",")})
|
||||
).root_plan_id
|
||||
if accounts_to_add := project._get_analytic_accounts().filtered(
|
||||
lambda account: account.root_plan_id not in applied_root_plans
|
||||
):
|
||||
line.analytic_distribution = {
|
||||
f"{account_ids},{','.join(map(str, accounts_to_add.ids))}": percentage
|
||||
for account_ids, percentage in line.analytic_distribution.items()
|
||||
}
|
||||
else:
|
||||
line.analytic_distribution = project._get_analytic_distribution()
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
lines = super().create(vals_list)
|
||||
lines._recompute_recordset(fnames=['analytic_distribution'])
|
||||
return lines
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue