Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contract/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions contract_timesheet_invoice_type/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
3 changes: 3 additions & 0 deletions contract_timesheet_invoice_type/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Comment thread
mileo marked this conversation as resolved.
)

@api.depends("contract_line_id.product_id", "amount")
Expand Down
36 changes: 36 additions & 0 deletions contract_timesheet_invoice_type/models/contract_contract.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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",
)
29 changes: 29 additions & 0 deletions contract_timesheet_invoice_type/models/project_task.py
Original file line number Diff line number Diff line change
@@ -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",
)
30 changes: 30 additions & 0 deletions contract_timesheet_invoice_type/views/contract_contract.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="contract_project_form_view" model="ir.ui.view">
<field name="model">contract.contract</field>
<field name="inherit_id" ref="contract.contract_contract_customer_form_view" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button
class="oe_stat_button"
name="action_view_projects"
type="object"
icon="fa-edit"
attrs="{'invisible': [('project_count', '=', 0)]}"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_value">
<field name="project_count" />
</span>
<span class="o_stat_text">Projects</span>
</div>
</button>
</xpath>
</field>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="project_sale_line_employee_map_form_view">
<field name="model">project.project</field>
<field name="inherit_id" ref="sale_timesheet.project_project_view_form"/>
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='sale_line_id']" position="before">
<field name="contract_id" optional="hide"/>
<field name="contract_line_id" optional="hide"/>
</xpath>
</field>
</record>

</odoo>
22 changes: 22 additions & 0 deletions contract_timesheet_invoice_type/views/project_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="project_task_form_view">
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_phone']" position="after">
<field name="contract_id" attrs="{'invisible': True}" groups="sales_team.group_sale_salesman"/>
<field name="contract_line_id" groups="sales_team.group_sale_salesman"/>
</xpath>
<xpath expr="//field[@name='timesheet_ids']/tree/field[@name='unit_amount']" position="before">
<!-- <field name="timesheet_ids"/> is already inside a block groups="hr_timesheet.group_hr_timesheet_user" -->
<field name="contract_line_id" />
</xpath>
</field>
</record>

</odoo>