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

+7
View File
@@ -0,0 +1,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import ir_model
from . import project_project
from . import project_task
from . import project_task_recurrence
from . import worksheet_template
+17
View File
@@ -0,0 +1,17 @@
from odoo import api, models
from odoo.tools.sql import column_exists
class IrModel(models.Model):
_inherit = "ir.model"
@api.ondelete(at_uninstall=True)
def _unlink_if_uninstalling(self):
# If module 'worksheet' is also being uninstalled, then column 'model_id'
# has already been dropped. That's simply because ir.model.fields records
# are deleted before ir.model records. In that situation, the call to
# search() below simply crashes because of the missing column.
if column_exists(self.env.cr, "worksheet_template", "model_id"):
self.env["worksheet.template"].with_context(active_test=False).search(
[("model_id", "in", self.ids)]
).unlink()
@@ -0,0 +1,59 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ProjectProject(models.Model):
_inherit = "project.project"
allow_worksheets = fields.Boolean(
"Worksheets", compute="_compute_allow_worksheets", store=True, readonly=False)
worksheet_template_id = fields.Many2one(
'worksheet.template', compute="_compute_worksheet_template_id", store=True, readonly=False,
string="Worksheet Template",
domain="[('res_model', '=', 'project.task'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
@api.depends('is_fsm')
def _compute_allow_worksheets(self):
for project in self:
project.allow_worksheets = project.is_fsm
@api.depends('allow_worksheets', 'company_id')
def _compute_worksheet_template_id(self):
default_worksheet = self.env.ref('industry_fsm_report.fsm_worksheet_template', False)
project_ids = []
for project in self:
if not project.worksheet_template_id:
if project.allow_worksheets:
if default_worksheet and (not project.company_id or not default_worksheet.company_id or project.company_id in default_worksheet.company_id):
project.worksheet_template_id = default_worksheet
else:
project_ids.append(project.id)
else:
project.worksheet_template_id = False
elif (project.allow_worksheets and project.company_id != project.worksheet_template_id.company_id):
project_ids.append(project.id)
if project_ids:
projects = self.browse(project_ids)
WorksheetTemplate = self.env['worksheet.template']
if len(projects.company_id) == 1:
projects.worksheet_template_id = WorksheetTemplate.search(
[('company_id', 'in', [projects.company_id.id, False]), ('res_model', '=', 'project.task')],
limit=1,
order="company_id, sequence, id DESC",
)
else:
company_worksheets = WorksheetTemplate._read_group(
[('company_id', 'in', [*projects.company_id.ids, False]), ('res_model', '=', 'project.task')],
['company_id'],
['id:recordset'],
)
worksheet_mapping = {company.id: templates.sorted(key=lambda t: (t.sequence, -t.id))[:1] for company, templates in company_worksheets}
# Assign the appropriate worksheet template to each project
for project in projects:
project.worksheet_template_id = worksheet_mapping.get(
project.company_id.id,
worksheet_mapping.get(False, False) # Fallback to a template without a company
)
+160
View File
@@ -0,0 +1,160 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from ast import literal_eval
from odoo import api, fields, models, _
class ProjectTask(models.Model):
_inherit = "project.task"
allow_worksheets = fields.Boolean(related='project_id.allow_worksheets')
worksheet_template_id = fields.Many2one(
'worksheet.template', string="Worksheet Template",
compute='_compute_worksheet_template_id', store=True, readonly=False, tracking=True,
domain="[('res_model', '=', 'project.task'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]",
group_expand='_group_expand_worksheet_template_id',
help="Create templates for each type of intervention you have and customize their content with your own custom fields.")
worksheet_count = fields.Integer(compute='_compute_worksheet_count', compute_sudo=True, export_string_translation=False)
@property
def TASK_PORTAL_READABLE_FIELDS(self):
return super().TASK_PORTAL_READABLE_FIELDS | {
'allow_worksheets',
'worksheet_count',
'worksheet_template_id',
}
@api.depends('worksheet_count', 'allow_worksheets')
def _compute_display_conditions_count(self):
super()._compute_display_conditions_count()
for task in self:
enabled = task.display_enabled_conditions_count
satisfied = task.display_satisfied_conditions_count
enabled += task.allow_worksheets
satisfied += task.allow_worksheets and task.worksheet_count
task.update({
'display_enabled_conditions_count': enabled,
'display_satisfied_conditions_count': satisfied
})
@api.depends(
'allow_worksheets', 'timer_start', 'worksheet_signature',
'display_satisfied_conditions_count', 'display_enabled_conditions_count',
)
def _compute_display_sign_report_buttons(self):
for task in self:
sign_p, sign_s = True, True
if (
not task.allow_worksheets
or task.sudo().timer_start
or task.worksheet_signature
or not task.display_satisfied_conditions_count
):
sign_p, sign_s = False, False
else:
if task.display_enabled_conditions_count == task.display_satisfied_conditions_count:
sign_s = False
else:
sign_p = False
task.update({
'display_sign_report_primary': sign_p,
'display_sign_report_secondary': sign_s,
})
@api.depends(
'allow_worksheets', 'timer_start', 'display_satisfied_conditions_count',
'display_enabled_conditions_count', 'fsm_is_sent',
)
def _compute_display_send_report_buttons(self):
for task in self:
send_p, send_s = True, True
if (
not task.allow_worksheets
or task.sudo().timer_start
or not task.display_satisfied_conditions_count
or task.fsm_is_sent
):
send_p, send_s = False, False
else:
if task.display_enabled_conditions_count == task.display_satisfied_conditions_count:
send_s = False
else:
send_p = False
task.update({
'display_send_report_primary': send_p,
'display_send_report_secondary': send_s,
})
@api.depends('project_id')
def _compute_worksheet_template_id(self):
# Change worksheet when the project changes, not project.allow_worksheet
for task in self:
if not task.worksheet_template_id and task.allow_worksheets:
task.worksheet_template_id = task.parent_id.worksheet_template_id.id\
if task.parent_id else task.project_id.worksheet_template_id.id
@api.depends('worksheet_template_id')
def _compute_worksheet_count(self):
for record in self:
worksheet_count = 0
if record.worksheet_template_id:
Worksheet = self.env[record.worksheet_template_id.sudo().model_id.model]
worksheet_count = Worksheet.search_count([('x_project_task_id', 'in', record.ids)])
record.worksheet_count = worksheet_count
@api.model
def _group_expand_worksheet_template_id(self, worksheets, domain):
start_date = self.env.context.get('gantt_start_date')
scale = self.env.context.get('gantt_scale')
if not (start_date and scale):
return worksheets
domain = self._expand_domain_dates(domain)
search_on_comodel = self._search_on_comodel(domain, "worksheet_template_id", "worksheet.template")
if search_on_comodel:
return search_on_comodel
else:
return self.search(domain).worksheet_template_id
def action_fsm_worksheet(self):
if self.env.user.has_group('industry_fsm.group_fsm_manager'):
worksheets_count = self.env['worksheet.template'].search_count([('res_model', '=', 'project.task')], limit=2)
if worksheets_count == 1:
current_template = self.worksheet_template_id
if not current_template.worksheet_count and current_template.name == 'Default Worksheet':
wizard = self.env['worksheet.template.load.wizard'].create({'task_id': self.id})
action = {
'name': _('Explore Worksheets Using an Example Template'),
'type': 'ir.actions.act_window',
'res_model': 'worksheet.template.load.wizard',
'views': [[False, 'form']],
'view_id': 'view_worksheet_template_load_form',
'target': 'new',
'res_id': wizard.id,
}
return action
return self.open_fsm_worksheet()
def open_fsm_worksheet(self):
action = self.worksheet_template_id.action_id.sudo().read()[0]
worksheet = self.env[self.worksheet_template_id.sudo().model_id.model].search([('x_project_task_id', '=', self.id)])
context = literal_eval(action.get('context', '{}'))
action.update({
'res_id': worksheet.id,
'views': [(False, 'form')],
'context': {
**context,
'edit': True,
'default_x_project_task_id': self.id,
},
})
return action
def _get_action_fsm_task_mobile_view(self):
action = super()._get_action_fsm_task_mobile_view()
action['context']['industry_fsm_has_same_worksheet_template'] = self.worksheet_template_id == self.project_id.sudo().worksheet_template_id
return action
def _is_fsm_report_available(self):
self.ensure_one()
return super()._is_fsm_report_available() or self.worksheet_count
@@ -0,0 +1,11 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
class ProjectTaskRecurrence(models.Model):
_inherit = 'project.task.recurrence'
@api.model
def _get_recurring_fields_to_copy(self):
return ['worksheet_template_id'] + super()._get_recurring_fields_to_copy()
@@ -0,0 +1,119 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from ast import literal_eval
from odoo import Command, api, models
class WorksheetTemplate(models.Model):
_inherit = 'worksheet.template'
def action_analysis_report(self):
res = super().action_analysis_report()
res['context'] = dict(literal_eval(res.get('context', '{}')), fsm_mode=True)
return res
def action_archive(self):
res = super().action_archive()
projects = self.env['project.project'].search([('worksheet_template_id', 'in', self.ids)])
projects.worksheet_template_id = False
return res
@api.model
def _get_models_to_check_dict(self):
res = super()._get_models_to_check_dict()
res['project.task'] = [('project.task', 'Task'), ('project.project', 'Project')]
return res
@api.model
def _get_project_task_user_group(self):
return self.env.ref('project.group_project_user')
@api.model
def _get_project_task_manager_group(self):
return self.env.ref('project.group_project_manager')
@api.model
def _get_project_task_access_all_groups(self):
return self.env.ref('project.group_project_manager') | self.env.ref('industry_fsm.group_fsm_user')
@api.model
def _get_project_task_module_name(self):
return 'industry_fsm_report'
def _get_project_task_additional_ir_rule_vals_list(self, name, model_id):
res_model = self.res_model.replace('.', '_')
return [
{
'name': f'{name}_user',
'model_id': model_id,
'domain_force': f"[(f'x_{res_model}_id.user_ids', 'in', user.id)]",
'groups': [Command.set(self._get_project_task_user_group().ids)],
},
]
def _get_template_action_context(self):
context = super()._get_template_action_context()
if self.res_model == 'project.task':
context.update({
'action_xml_id': 'industry_fsm_report.fsm_worksheets_action_settings',
'worksheet_template_id': self.id,
})
return context
def get_x_model_form_action(self):
action = super().get_x_model_form_action()
if self.res_model == 'project.task':
action['context'].update({'action_xml_id': 'industry_fsm_report.fsm_worksheets_action_settings', 'worksheet_template_id': self.id})
return action
@api.model
def _create_demo_data_fsm(self, model_id=False):
# create demo data in batch for performance reasons (avoid multiple calls to _setup_models__)
if not model_id:
model_id = self.env.ref('industry_fsm_report.fsm_worksheet_template2').model_id.id
self.env['ir.model.fields'].with_context(_import_current_module='industry_fsm_report', noupdate=True).create([{
'id': 'fsm_template_field1',
'name': 'x_intervention_type',
'ttype': 'selection',
'field_description': 'Intervention Type',
'selection': "[('first_installation','First installation'),('technical_maintenance','Technical maintenance')]",
'model_id': model_id,
}, {
'id': 'fsm_template_field2',
'name': 'x_description',
'ttype': 'text',
'field_description': 'Description of the Intervention',
'model_id': model_id,
}, {
'id': 'fsm_template_field3',
'name': 'x_manufacturer',
'ttype': 'many2one',
'relation': 'res.partner',
'field_description': 'Manufacturer',
'model_id': model_id,
}, {
'id': 'fsm_template_field4',
'name': 'x_checkbox',
'ttype': 'boolean',
'field_description': 'I hereby certify that this device meets the requirements of an acceptable device at the time of testing.',
'model_id': model_id,
}, {
'id': 'fsm_template_field5',
'name': 'x_serial_number',
'ttype': 'char',
'field_description': 'Serial Number',
'model_id': model_id,
}, {
'id': 'fsm_template_field6',
'name': 'x_date',
'ttype': 'date',
'field_description': 'Date',
'model_id': model_id,
}, {
'id': 'fsm_template_field7',
'name': 'x_worker_signature',
'ttype': 'binary',
'field_description': 'Technician Signature',
'model_id': model_id,
}])