diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index ab1ecd0015..88c00a4d0c 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -22,6 +22,7 @@ class ContractLine(models.Model): "analytic.mixin", ] _order = "sequence,id" + _rec_names_search = ["name", "contract_id.name"] sequence = fields.Integer() contract_id = fields.Many2one( @@ -1094,3 +1095,15 @@ def _get_quantity_to_invoice( ): self.ensure_one() return self.quantity if not self.display_type else 0.0 + + def name_get(self): + result = [] + for record in self.sudo(): + name = "%s - %s" % ( + record.contract_id.name, + record.name and record.name.split("\n")[0] or record.product_id.name, + ) + if record.contract_id.code: + name = "%s (%s)" % (name, record.contract_id.code) + result.append((record.id, name)) + return result diff --git a/contract_timesheet_invoice_type/__manifest__.py b/contract_timesheet_invoice_type/__manifest__.py index 0d09d4e29a..f15d63c41b 100644 --- a/contract_timesheet_invoice_type/__manifest__.py +++ b/contract_timesheet_invoice_type/__manifest__.py @@ -15,6 +15,9 @@ "sale_timesheet", ], "data": [ + 'views/project_task.xml', + 'views/contract_contract.xml', + 'views/project_sale_line_employee_map.xml', "views/project_project.xml", ], "maintainer": ["sbidoul"], diff --git a/contract_timesheet_invoice_type/models/__init__.py b/contract_timesheet_invoice_type/models/__init__.py index aaefbcd7b0..aa9acad56f 100644 --- a/contract_timesheet_invoice_type/models/__init__.py +++ b/contract_timesheet_invoice_type/models/__init__.py @@ -1,2 +1,5 @@ from . import account_analytic_line from . import project_project +from . import project_sale_line_employee_map +from . import contract_contract +from . import project_task diff --git a/contract_timesheet_invoice_type/models/account_analytic_line.py b/contract_timesheet_invoice_type/models/account_analytic_line.py index f08960660e..0be63a71cb 100644 --- a/contract_timesheet_invoice_type/models/account_analytic_line.py +++ b/contract_timesheet_invoice_type/models/account_analytic_line.py @@ -8,7 +8,7 @@ class AccountAnalyticLine(models.Model): _inherit = "account.analytic.line" contract_line_id = fields.Many2one( - related="project_id.contract_line_id", + comodel_name="contract.line" ) @api.depends("contract_line_id.product_id", "amount") diff --git a/contract_timesheet_invoice_type/models/contract_contract.py b/contract_timesheet_invoice_type/models/contract_contract.py new file mode 100644 index 0000000000..f73037e372 --- /dev/null +++ b/contract_timesheet_invoice_type/models/contract_contract.py @@ -0,0 +1,36 @@ +# Copyright 2024 KMEE +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class ContractContract(models.Model): + + _inherit = "contract.contract" + + project_ids = fields.One2many( + 'project.project', + 'contract_id', + ) + + project_count = fields.Integer(compute="_compute_project_count") + + @api.depends("project_ids") + def _compute_project_count(self): + for rec in self: + rec.project_count = len(rec.project_ids) + + def action_view_projects(self): + self.ensure_one() + projects = self.project_ids + action = { + "name": _("Projects"), + "view_mode": "tree,form", + "res_model": "project.project", + "type": "ir.actions.act_window", + "domain": [("id", "in", projects.ids)], + } + if len(projects) == 1: + # If there is only one order, open it directly + action.update({"view_mode": "form", "res_id": projects.id}) + return action diff --git a/contract_timesheet_invoice_type/models/project_sale_line_employee_map.py b/contract_timesheet_invoice_type/models/project_sale_line_employee_map.py new file mode 100644 index 0000000000..61187040f2 --- /dev/null +++ b/contract_timesheet_invoice_type/models/project_sale_line_employee_map.py @@ -0,0 +1,29 @@ +# Copyright 2024 KMEE +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class ProjectSaleLineEmployeeMap(models.Model): + + _inherit = "project.sale.line.employee.map" + + contract_line_id = fields.Many2one( + "contract.line", + "Contract Item", + copy=False, + index="btree_not_null", + # domain=( + # "[('partner_id', '=?', partner_id), " + # "'|', ('company_id', '=', False), ('company_id', '=', company_id)]" + # ), + help=( + "Recurring invoicing contract item that will be used to " + "determine the timesheet invoicing type." + ), + ) + contract_id = fields.Many2one( + related="contract_line_id.contract_id", + readonly=True, + help="Recurring invoicing contract", + ) diff --git a/contract_timesheet_invoice_type/models/project_task.py b/contract_timesheet_invoice_type/models/project_task.py new file mode 100644 index 0000000000..7da44ec079 --- /dev/null +++ b/contract_timesheet_invoice_type/models/project_task.py @@ -0,0 +1,29 @@ +# Copyright 2024 KMEE +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models + + +class ProjectTask(models.Model): + + _inherit = "project.task" + + contract_line_id = fields.Many2one( + "contract.line", + "Contract Item", + copy=False, + # index="btree_not_null", + domain=( + "[('partner_id', '=?', partner_id), " + "'|', ('company_id', '=', False), ('company_id', '=', company_id)]" + ), + help=( + "Recurring invoicing contract item that will be used to " + "determine the timesheet invoicing type." + ), + ) + contract_id = fields.Many2one( + related="contract_line_id.contract_id", + readonly=True, + help="Recurring invoicing contract", + ) diff --git a/contract_timesheet_invoice_type/views/contract_contract.xml b/contract_timesheet_invoice_type/views/contract_contract.xml new file mode 100644 index 0000000000..696672eae6 --- /dev/null +++ b/contract_timesheet_invoice_type/views/contract_contract.xml @@ -0,0 +1,30 @@ + + + + + + + contract.contract + + + + + + + + + diff --git a/contract_timesheet_invoice_type/views/project_sale_line_employee_map.xml b/contract_timesheet_invoice_type/views/project_sale_line_employee_map.xml new file mode 100644 index 0000000000..b5569c8edb --- /dev/null +++ b/contract_timesheet_invoice_type/views/project_sale_line_employee_map.xml @@ -0,0 +1,18 @@ + + + + + + + project.project + + + + + + + + + + diff --git a/contract_timesheet_invoice_type/views/project_task.xml b/contract_timesheet_invoice_type/views/project_task.xml new file mode 100644 index 0000000000..d32e723df8 --- /dev/null +++ b/contract_timesheet_invoice_type/views/project_task.xml @@ -0,0 +1,22 @@ + + + + + + + project.task + + + + + + + + + + + + + +