19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo.tools import SQL
class UtmCampaign(models.Model):
_inherit = 'utm.campaign'
@ -11,21 +12,23 @@ class UtmCampaign(models.Model):
compute="_compute_quotation_count", compute_sudo=True, groups='sales_team.group_sale_salesman')
invoiced_amount = fields.Integer(string="Revenues generated by the campaign",
compute="_compute_sale_invoiced_amount", compute_sudo=True, groups='sales_team.group_sale_salesman')
company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company)
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company)
currency_id = fields.Many2one('res.currency', related='company_id.currency_id', string='Currency')
def _compute_quotation_count(self):
quotation_data = self.env['sale.order']._read_group([
('campaign_id', 'in', self.ids)],
['campaign_id'], ['campaign_id'])
data_map = {datum['campaign_id'][0]: datum['campaign_id_count'] for datum in quotation_data}
['campaign_id'], ['__count'])
data_map = {campaign.id: count for campaign, count in quotation_data}
for campaign in self:
campaign.quotation_count = data_map.get(campaign.id, 0)
def _compute_sale_invoiced_amount(self):
self.env['account.move.line'].flush_model(['balance', 'move_id', 'account_id', 'display_type'])
self.env['account.move'].flush_model(['state', 'campaign_id', 'move_type'])
query = """SELECT move.campaign_id, -SUM(line.balance) as price_subtotal
if self.ids:
self.env['account.move.line'].flush_model(['balance', 'move_id', 'account_id', 'display_type'])
self.env['account.move'].flush_model(['state', 'campaign_id', 'move_type'])
query_res = self.env.execute_query_dict(SQL(
""" SELECT move.campaign_id, -SUM(line.balance) as price_subtotal
FROM account_move_line line
INNER JOIN account_move move ON line.move_id = move.id
WHERE move.state not in ('draft', 'cancel')
@ -33,11 +36,11 @@ class UtmCampaign(models.Model):
AND move.move_type IN ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt')
AND line.account_id IS NOT NULL
AND line.display_type = 'product'
GROUP BY move.campaign_id
"""
self._cr.execute(query, [tuple(self.ids)])
query_res = self._cr.dictfetchall()
GROUP BY move.campaign_id """,
tuple(self.ids),
))
else:
query_res = []
campaigns = self.browse()
for datum in query_res: