Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] contract_timesheet_invoice_type #1101

Draft
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
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
1 change: 1 addition & 0 deletions contract/models/contract_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ContractLine(models.Model):
)
company_id = fields.Many2one(related="contract_id.company_id")
currency_id = fields.Many2one(related="contract_id.currency_id")
partner_id = fields.Many2one(related="contract_id.partner_id")
date_start = fields.Date(required=True)
date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False)
termination_notice_date = fields.Date(
Expand Down
96 changes: 96 additions & 0 deletions contract_timesheet_invoice_type/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
==================
Contract Timesheet
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7dda3119071689c61cea26bb92ceabe337c1a6d207437833caa853f9170c5ab0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
:target: https://github.com/OCA/contract/tree/16.0/contract_timesheet_invoice_type
:alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract_timesheet_invoice_type
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This modules adds a Contract field on projects, and sets the timesheet
invoice type based on the product that is used on the contract line.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Timesheets have a ``timesheet_invoice_type`` field which tells if they
are billable or not, and if billable of which type. In the
``sale_timesheet`` module, this field gets a billable type only when the
timesheet are linked to a sale order line.

When billing with recurring invoices using the OCA ``contract`` module,
we often work without sale order. So this module is useful to allow
correctly categorizing as billable timesheets on projects that are
billed using recurring contracts.

Known issues / Roadmap
======================

- A link between tasks and contract lines could be added, similar to
what is done for sale order line.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract_timesheet_invoice_type%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Stéphane Bidoul [email protected]

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/16.0/contract_timesheet_invoice_type>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions contract_timesheet_invoice_type/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions contract_timesheet_invoice_type/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Contract Timesheet",
"summary": """
Link projects to sale contracts""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/contract",
"depends": [
"contract",
"sale_project",
"sale_timesheet",
],
"data": [
"views/project_project.xml",
],
"maintainer": ["sbidoul"],
}
2 changes: 2 additions & 0 deletions contract_timesheet_invoice_type/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_analytic_line
from . import project_project
41 changes: 41 additions & 0 deletions contract_timesheet_invoice_type/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 ASCONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class AccountAnalyticLine(models.Model):
_inherit = "account.analytic.line"

contract_line_id = fields.Many2one(
related="project_id.contract_line_id",
)

@api.depends("contract_line_id.product_id", "amount")
def _compute_timesheet_invoice_type(self): # pylint: disable=missing-return
super()._compute_timesheet_invoice_type()

Check warning on line 16 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L16

Added line #L16 was not covered by tests
for rec in self:
if rec.so_line:
# billed via the sale order
continue

Check warning on line 20 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L20

Added line #L20 was not covered by tests
if not rec.contract_line_id:
# no contract, let the default algo do it's job
continue

Check warning on line 23 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L23

Added line #L23 was not covered by tests
# From here, similar algorithm as in sale_timesheet
product_id = rec.contract_line_id.product_id

Check warning on line 25 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L25

Added line #L25 was not covered by tests
if product_id.type != "service":
continue

Check warning on line 27 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L27

Added line #L27 was not covered by tests
if product_id.invoice_policy == "delivery":
service_type = product_id.service_type

Check warning on line 29 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L29

Added line #L29 was not covered by tests
if service_type == "timesheet":
rec.timesheet_invoice_type = (

Check warning on line 31 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L31

Added line #L31 was not covered by tests
"timesheet_revenues" if rec.amount > 0 else "billable_time"
)
else:
rec.timesheet_invoice_type = (

Check warning on line 35 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L35

Added line #L35 was not covered by tests
f"billable_{service_type}"
if service_type in ["milestones", "manual"]
else "billable_fixed"
)
elif product_id.invoice_policy == "order":
rec.timesheet_invoice_type = "billable_fixed"

Check warning on line 41 in contract_timesheet_invoice_type/models/account_analytic_line.py

View check run for this annotation

Codecov / codecov/patch

contract_timesheet_invoice_type/models/account_analytic_line.py#L41

Added line #L41 was not covered by tests
28 changes: 28 additions & 0 deletions contract_timesheet_invoice_type/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 ASCONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProjectProject(models.Model):
_inherit = "project.project"

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",
)
9 changes: 9 additions & 0 deletions contract_timesheet_invoice_type/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Timesheets have a `timesheet_invoice_type` field which tells if they are
billable or not, and if billable of which type. In the `sale_timesheet` module,
this field gets a billable type only when the timesheet are linked to a sale
order line.

When billing with recurring invoices using the OCA `contract` module, we often
work without sale order. So this module is useful to allow correctly
categorizing as billable timesheets on projects that are billed using recurring
contracts.
1 change: 1 addition & 0 deletions contract_timesheet_invoice_type/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Stéphane Bidoul <[email protected]>
2 changes: 2 additions & 0 deletions contract_timesheet_invoice_type/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This modules adds a Contract field on projects, and sets the timesheet invoice
type based on the product that is used on the contract line.
2 changes: 2 additions & 0 deletions contract_timesheet_invoice_type/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- A link between tasks and contract lines could be added, similar to what is done
for sale order line.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading