chore: import enterprise addons 19.0 bulk snapshot

This commit is contained in:
1b-agent committed 2026-09-16 10:13:08 +00:00
commit ca4af030d3
39951 files changed
+15570005

No files matched your search

@@ -0,0 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import budget_line
from . import purchase_order
from . import purchase_order_line
@@ -0,0 +1,32 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class BudgetLine(models.Model):
_inherit = 'budget.line'
committed_amount = fields.Monetary(
compute='_compute_all',
string='Committed',
help="Already Billed amount + Confirmed purchase orders.")
committed_percentage = fields.Float(
compute='_compute_all',
string='Committed (%)')
def _compute_all(self):
# Override in order to do only one read_group
grouped = {
line: (committed, achieved)
for line, committed, achieved in self.env['budget.report']._read_group(
domain=[('budget_line_id', 'in', self.ids)],
groupby=['budget_line_id'],
aggregates=['committed:sum', 'achieved:sum'],
)
}
for line in self:
committed, achieved = grouped.get(line, (0, 0))
line.committed_amount = committed
line.achieved_amount = achieved
line.committed_percentage = line.budget_amount and (line.committed_amount / line.budget_amount)
line.achieved_percentage = line.budget_amount and (line.achieved_amount / line.budget_amount)
@@ -0,0 +1,37 @@
from odoo import fields, models, api
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
is_above_budget = fields.Boolean('Is Above Budget', compute='_compute_above_budget')
is_analytic = fields.Boolean('Is Analytic', compute='_compute_is_analytic')
@api.depends('order_line.analytic_distribution')
def _compute_is_analytic(self):
for order in self:
order.is_analytic = any(order.order_line.mapped('analytic_distribution'))
@api.depends('order_line.budget_line_ids', 'order_line.price_unit', 'order_line.product_qty', 'order_line.qty_invoiced', 'state')
def _compute_above_budget(self):
for order in self:
uncommitted_amount = sum(
line.price_unit * (line.product_qty - line.qty_invoiced)
for line in order.order_line if line.budget_line_ids
) if order.state not in ('purchase', 'done') else 0
order.is_above_budget = any(
budget.committed_amount + uncommitted_amount > budget.budget_amount
for budget in order.order_line.mapped('budget_line_ids')
)
def action_budget(self):
self.ensure_one()
analytic_account_ids = [
int(account)
for line in self.order_line
for account_ids in (line.analytic_distribution or {})
for account in account_ids.split(',')
]
action = self.env["ir.actions.actions"]._for_xml_id("account_budget.budget_report_action")
action['domain'] = [('auto_account_id', 'in', analytic_account_ids), ('budget_analytic_id.budget_type', '!=', 'revenue')]
return action
@@ -0,0 +1,63 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
analytic_json = fields.Json('Analytic JSON', compute='_compute_analytic_json', store=True)
is_above_budget = fields.Boolean('Is Above Budget', compute='_compute_above_budget')
budget_line_ids = fields.One2many('budget.line', compute='_compute_budget_line_ids', string='Budget Lines')
@api.depends('analytic_distribution')
def _compute_analytic_json(self):
for line in self:
distribution = []
for analytic_account_ids, percentage in (line.analytic_distribution or {}).items():
dist_dict = {'rate': float(percentage) / 100}
for analytic_account in self.env['account.analytic.account'].browse(map(int, analytic_account_ids.split(","))).exists():
root_plan = analytic_account.root_plan_id
dist_dict[root_plan._column_name()] = analytic_account.id
distribution.append(dist_dict)
line.analytic_json = distribution
@api.depends('analytic_distribution')
def _compute_budget_line_ids(self):
def get_domain(line):
if not self.env['budget.analytic'].has_access('read'):
return False
if line.analytic_json and line.product_qty - line.qty_received > 0:
project_plan, other_plans = self.env['account.analytic.plan']._get_all_plans()
domain_to_add = set()
for plan in project_plan + other_plans:
domain_to_add.add(plan._column_name())
for json in line.analytic_json:
domain = [
('budget_analytic_id', 'any', (
('budget_type', '!=', 'revenue'),
('state', '=', 'confirmed'),
)),
('date_from', '<=', line.order_id.date_order),
('date_to', '>=', line.order_id.date_order),
]
for key, value in json.items():
if key in self.env['budget.line']._fields:
domain += [(key, '=', value)]
domain_to_add.discard(key)
for key in domain_to_add:
domain += [(key, '=', False)]
return tuple(domain)
for domain, lines in self.grouped(get_domain).items():
budget_lines = bool(domain) and self.env['budget.line'].search(list(domain))
for line in lines:
line.budget_line_ids = budget_lines
@api.depends('budget_line_ids', 'price_unit', 'product_qty', 'qty_invoiced')
def _compute_above_budget(self):
for line in self:
uncommitted_amount = 0
if line.order_id.state != 'purchase':
uncommitted_amount = line.price_unit * (line.product_qty - line.qty_invoiced)
line.is_above_budget = any(budget.committed_amount + uncommitted_amount > budget.budget_amount for budget in line.budget_line_ids)