mirror of
https://github.com/bringout/oca-ocb-project.git
synced 2026-04-22 06:02:02 +02:00
19.0 vanilla
This commit is contained in:
parent
a2f74aefd8
commit
4a4d12c333
844 changed files with 212348 additions and 270090 deletions
|
|
@ -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