[MIG] contract_variable_qty_timesheet: Migration to 16.0

This commit is contained in:
Daniel Palomar
2024-08-07 08:59:58 +02:00
parent 85355376c2
commit 4f4c4656dc
9 changed files with 97 additions and 47 deletions

View File

@@ -17,13 +17,13 @@ Contract Variable Qty Timesheet
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
:target: https://github.com/OCA/contract/tree/15.0/contract_variable_qty_timesheet :target: https://github.com/OCA/contract/tree/16.0/contract_variable_qty_timesheet
:alt: OCA/contract :alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/contract-15-0/contract-15-0-contract_variable_qty_timesheet :target: https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract_variable_qty_timesheet
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=15.0 :target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0
:alt: Try me on Runboat :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@@ -55,7 +55,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_. 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. 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 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_variable_qty_timesheet%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract_variable_qty_timesheet%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. Do not contact contributors directly about support or help with technical issues.
@@ -80,6 +80,10 @@ Contributors
* Fernando La Chica <fernandolachica@gmail.com> * Fernando La Chica <fernandolachica@gmail.com>
* `Coopdevs Treball <https://coopdevs.coop>`_:
* Daniel Palomar <daniel.palomar@coopdevs.org>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@@ -99,11 +103,14 @@ promote its widespread use.
.. |maintainer-pedrobaeza| image:: https://github.com/pedrobaeza.png?size=40px .. |maintainer-pedrobaeza| image:: https://github.com/pedrobaeza.png?size=40px
:target: https://github.com/pedrobaeza :target: https://github.com/pedrobaeza
:alt: pedrobaeza :alt: pedrobaeza
.. |maintainer-danypr92| image:: https://github.com/danypr92.png?size=40px
:target: https://github.com/danypr92
:alt: danypr92
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__: Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-carlosdauden| |maintainer-pedrobaeza| |maintainer-carlosdauden| |maintainer-pedrobaeza| |maintainer-danypr92|
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/15.0/contract_variable_qty_timesheet>`_ project on GitHub. This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/16.0/contract_variable_qty_timesheet>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -5,7 +5,7 @@
{ {
"name": "Contract Variable Qty Timesheet", "name": "Contract Variable Qty Timesheet",
"summary": "Add formula to invoice ", "summary": "Add formula to invoice ",
"version": "15.0.1.0.0", "version": "16.0.1.0.0",
"category": "Contract Management", "category": "Contract Management",
"website": "https://github.com/OCA/contract", "website": "https://github.com/OCA/contract",
"author": "Tecnativa, " "Odoo Community Association (OCA)", "author": "Tecnativa, " "Odoo Community Association (OCA)",
@@ -13,5 +13,5 @@
"installable": True, "installable": True,
"depends": ["contract_variable_quantity", "hr_timesheet"], "depends": ["contract_variable_quantity", "hr_timesheet"],
"data": ["data/contract_line_qty_formula_data.xml"], "data": ["data/contract_line_qty_formula_data.xml"],
"maintainers": ["carlosdauden", "pedrobaeza"], "maintainers": ["carlosdauden", "pedrobaeza", "danypr92"],
} }

View File

@@ -8,8 +8,10 @@
model="contract.line.qty.formula" model="contract.line.qty.formula"
> >
<field name='name'>Project Timesheets</field> <field name='name'>Project Timesheets</field>
<field name="code">group = env['account.analytic.line'].read_group([ <field name="code">
('account_id', '=', line.analytic_account_id.id), account_analytic_ids = line.analytic_distribution and [int(_id) for _id in list(line.analytic_distribution.keys())] or []
group = env['account.analytic.line'].read_group([
('account_id', 'in', account_analytic_ids),
('product_id', '=', False), ('product_id', '=', False),
('project_id', '!=', False), ('project_id', '!=', False),
('date', '&gt;=', period_first_date), ('date', '&gt;=', period_first_date),
@@ -23,8 +25,10 @@ result = group and group[0]['unit_amount'] or 0.0
model="contract.line.qty.formula" model="contract.line.qty.formula"
> >
<field name='name'>Task Timesheets</field> <field name='name'>Task Timesheets</field>
<field name="code">group = env['account.analytic.line'].read_group([ <field name="code">
('account_id', '=', line.analytic_account_id.id), account_analytic_ids = line.analytic_distribution and [int(_id) for _id in list(line.analytic_distribution.keys())] or []
group = env['account.analytic.line'].read_group([
('account_id', 'in', account_analytic_ids),
('product_id', '=', False), ('product_id', '=', False),
('task_id', '!=', False), ('task_id', '!=', False),
('date', '&gt;=', period_first_date), ('date', '&gt;=', period_first_date),
@@ -38,8 +42,10 @@ result = group and group[0]['unit_amount'] or 0.0
model="contract.line.qty.formula" model="contract.line.qty.formula"
> >
<field name='name'>Analytic Same Product</field> <field name='name'>Analytic Same Product</field>
<field name="code">group = env['account.analytic.line'].read_group([ <field name="code">
('account_id', '=', line.analytic_account_id.id), account_analytic_ids = line.analytic_distribution and [int(_id) for _id in list(line.analytic_distribution.keys())] or []
group = env['account.analytic.line'].read_group([
('account_id', 'in', account_analytic_ids),
('product_id', '=', line.product_id.id), ('product_id', '=', line.product_id.id),
('date', '&gt;=', period_first_date), ('date', '&gt;=', period_first_date),
('date', '&lt;=', period_last_date), ('date', '&lt;=', period_last_date),

View File

@@ -7,3 +7,7 @@
* `Guadaltech <https://www.guadaltech.es>`_: * `Guadaltech <https://www.guadaltech.es>`_:
* Fernando La Chica <fernandolachica@gmail.com> * Fernando La Chica <fernandolachica@gmail.com>
* `Coopdevs Treball <https://coopdevs.coop>`_:
* Daniel Palomar <daniel.palomar@coopdevs.org>

View File

@@ -1,6 +1,6 @@
To use this module, you need to: To use this module, you need to:
#. Go to Invoicing > Sales > Contracts and select or create a new contract. #. Go to Invoicing > Customers > Customer Contracts and select or create a new contract.
#. Check *Generate recurring invoices automatically*. #. Check *Generate recurring invoices automatically*.
#. Add a new recurring invoicing line. #. Add a new recurring invoicing line.
#. Select "Variable quantity" in column "Qty. type". #. Select "Variable quantity" in column "Qty. type".

View File

@@ -0,0 +1,2 @@
# addons listed in this file are ignored by
# setuptools-odoo-make-default (one addon per line)

View File

@@ -0,0 +1,2 @@
To learn more about this directory, please visit
https://pypi.python.org/pypi/setuptools-odoo

View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
@@ -369,7 +368,7 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e5498feee850c8ae2cc09cbae0c07393069f065c83bca8823127e9eec40bbe1b !! source digest: sha256:e5498feee850c8ae2cc09cbae0c07393069f065c83bca8823127e9eec40bbe1b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/15.0/contract_variable_qty_timesheet"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-15-0/contract-15-0-contract_variable_qty_timesheet"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/16.0/contract_variable_qty_timesheet"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract_variable_qty_timesheet"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of contract_variable_quantity adding <p>This module extends the functionality of contract_variable_quantity adding
several variable quantity formulas to allow to invoice lines from Timesheet several variable quantity formulas to allow to invoice lines from Timesheet
(Analytic Lines).</p> (Analytic Lines).</p>
@@ -403,7 +402,7 @@ depending on your need.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20contract_variable_qty_timesheet%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20contract_variable_qty_timesheet%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@@ -427,6 +426,10 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li> <li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
</ul> </ul>
</li> </li>
<li><a class="reference external" href="https://coopdevs.coop">Coopdevs Treball</a>:<ul>
<li>Daniel Palomar &lt;<a class="reference external" href="mailto:daniel.palomar&#64;coopdevs.org">daniel.palomar&#64;coopdevs.org</a>&gt;</li>
</ul>
</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@@ -437,8 +440,8 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p> <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/carlosdauden"><img alt="carlosdauden" src="https://github.com/carlosdauden.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/pedrobaeza"><img alt="pedrobaeza" src="https://github.com/pedrobaeza.png?size=40px" /></a></p> <p><a class="reference external image-reference" href="https://github.com/carlosdauden"><img alt="carlosdauden" src="https://github.com/carlosdauden.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/pedrobaeza"><img alt="pedrobaeza" src="https://github.com/pedrobaeza.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/danypr92"><img alt="danypr92" src="https://github.com/danypr92.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/15.0/contract_variable_qty_timesheet">OCA/contract</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/16.0/contract_variable_qty_timesheet">OCA/contract</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@@ -2,44 +2,70 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields from odoo import fields
from odoo.tests import common from odoo.tests.common import TransactionCase
class TestContractVariableQtyTimesheet(common.TransactionCase): class TestContractVariableQtyTimesheet(TransactionCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.partner = cls.env["res.partner"].create({"name": "Test partner"}) cls.company = cls.env.company
cls.partner = cls.env["res.partner"].create(
{"name": "Test partner", "company_id": cls.company.id}
)
cls.plan = cls.env["account.analytic.plan"].create({"name": "Test Plan"})
cls.analytic_account = cls.env["account.analytic.account"].create( cls.analytic_account = cls.env["account.analytic.account"].create(
{"name": "Test analytic account"} {
"name": "Test analytic account",
"plan_id": cls.plan.id,
"company_id": cls.company.id,
}
) )
cls.contract = cls.env["contract.contract"].create( cls.contract = cls.env["contract.contract"].create(
{"name": "Test contract", "partner_id": cls.partner.id} {
"name": "Test contract",
"partner_id": cls.partner.id,
"company_id": cls.company.id,
}
)
cls.product = cls.env["product.product"].create(
{"name": "Test product", "company_id": cls.company.id}
)
cls.employee = cls.env["hr.employee"].create(
{
"name": "Test Employee",
"company_id": cls.company.id,
}
) )
cls.product = cls.env["product.product"].create({"name": "Test product"})
contract_line_vals = { contract_line_vals = {
"name": "Test contract line",
"contract_id": cls.contract.id, "contract_id": cls.contract.id,
"analytic_account_id": cls.analytic_account.id,
"product_id": cls.product.id,
"uom_id": cls.product.uom_id.id,
"name": "Test line contract",
"recurring_interval": 1,
"recurring_rule_type": "monthly",
"recurring_invoicing_type": "pre-paid",
"date_start": "2020-01-01", "date_start": "2020-01-01",
"recurring_next_date": "2020-01-01", "date_end": "2020-12-31",
"qty_type": "variable", "product_id": cls.product.id,
"qty_formula_id": cls.env.ref( "qty_formula_id": cls.env.ref(
"contract_variable_qty_timesheet." "contract_variable_qty_timesheet.contract_line_qty_formula_project_timesheet"
"contract_line_qty_formula_project_timesheet"
).id, ).id,
"sequence": 10,
"state": "in-progress",
"company_id": cls.company.id,
"qty_type": "variable",
"analytic_distribution": {str(cls.analytic_account.id): 100},
} }
cls.contract_line = cls.env["contract.line"].create(contract_line_vals) cls.contract_line = cls.env["contract.line"].create(contract_line_vals)
cls.project = cls.env["project.project"].create( cls.project = cls.env["project.project"].create(
{"name": "Test project", "analytic_account_id": cls.analytic_account.id} {
"name": "Test project",
"analytic_account_id": cls.analytic_account.id,
"company_id": cls.company.id,
}
) )
cls.task = cls.env["project.task"].create( cls.task = cls.env["project.task"].create(
{"project_id": cls.project.id, "name": "Test task"} {
"project_id": cls.project.id,
"name": "Test task",
"company_id": cls.company.id,
}
) )
def _contract_invoicing(self, contract): def _contract_invoicing(self, contract):
@@ -53,38 +79,38 @@ class TestContractVariableQtyTimesheet(common.TransactionCase):
"account_id": self.analytic_account.id, "account_id": self.analytic_account.id,
"project_id": project and project.id, "project_id": project and project.id,
"task_id": task and task.id, "task_id": task and task.id,
"name": "Test {} {}".format(date, unit_amount), "name": f"Test {date} {unit_amount}",
"date": date, "date": date,
"product_id": product and product.id, "product_id": product and product.id,
"unit_amount": unit_amount, "unit_amount": unit_amount,
"employee_id": self.employee.id,
"company_id": self.company.id,
} }
) )
def test_project_timesheet(self): def test_project_timesheet(self):
self._create_analytic_line(self.project, self.task, "2020-01-01", False, 3) self._create_analytic_line(self.project, self.task, "2020-01-01", False, 3)
self._create_analytic_line(False, False, "2020-01-01", False, 1) self._create_analytic_line(False, False, "2020-01-01", False, 1)
invoice = self._contract_invoicing(self.contract) invoice = self.contract._recurring_create_invoice()
self.assertEqual(len(invoice.invoice_line_ids), 1) self.assertEqual(len(invoice.invoice_line_ids), 1)
self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3) self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)
def test_task_timesheet(self): def test_task_timesheet(self):
self.contract_line.qty_formula_id = self.env.ref( self.contract_line.qty_formula_id = self.env.ref(
"contract_variable_qty_timesheet." "contract_variable_qty_timesheet.contract_line_qty_formula_task_timesheet"
"contract_line_qty_formula_task_timesheet"
).id ).id
self._create_analytic_line(self.project, self.task, "2020-01-01", False, 3) self._create_analytic_line(self.project, self.task, "2020-01-01", False, 3)
self._create_analytic_line(self.project, False, "2020-01-01", False, 1) self._create_analytic_line(self.project, False, "2020-01-01", False, 1)
invoice = self._contract_invoicing(self.contract) invoice = self.contract._recurring_create_invoice()
self.assertEqual(len(invoice.invoice_line_ids), 1) self.assertEqual(len(invoice.invoice_line_ids), 1)
self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3) self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)
def test_same_product(self): def test_same_product(self):
self.contract_line.qty_formula_id = self.env.ref( self.contract_line.qty_formula_id = self.env.ref(
"contract_variable_qty_timesheet." "contract_variable_qty_timesheet.contract_line_qty_formula_analytic_same_product"
"contract_line_qty_formula_analytic_same_product"
).id ).id
self._create_analytic_line(False, False, "2020-01-01", self.product, 3) self._create_analytic_line(False, False, "2020-01-01", self.product, 3)
self._create_analytic_line(self.project, False, "2020-01-01", False, 1) self._create_analytic_line(self.project, False, "2020-01-01", False, 1)
invoice = self._contract_invoicing(self.contract) invoice = self.contract._recurring_create_invoice()
self.assertEqual(len(invoice.invoice_line_ids), 1) self.assertEqual(len(invoice.invoice_line_ids), 1)
self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3) self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)