Skip to content

Commit 70faae4

Browse files
[MIG] contract: Migration to 19.0
1 parent 7e2a594 commit 70faae4

19 files changed

Lines changed: 157 additions & 208 deletions

contract/README.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Recurring - Contracts Management
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
24-
:target: https://github.com/OCA/contract/tree/18.0/contract
24+
:target: https://github.com/OCA/contract/tree/19.0/contract
2525
:alt: OCA/contract
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/contract-18-0/contract-18-0-contract
27+
:target: https://translation.odoo-community.org/projects/contract-19-0/contract-19-0-contract
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -98,9 +98,9 @@ Usage
9898

9999
|image2|
100100

101-
.. |image| image:: https://raw.githubusercontent.com/OCA/contract/18.0/contract/static/src/screenshots/portal-my.png
102-
.. |image1| image:: https://raw.githubusercontent.com/OCA/contract/18.0/contract/static/src/screenshots/portal-list.png
103-
.. |image2| image:: https://raw.githubusercontent.com/OCA/contract/18.0/contract/static/src/screenshots/portal-detail.png
101+
.. |image| image:: https://raw.githubusercontent.com/OCA/contract/19.0/contract/static/src/screenshots/portal-my.png
102+
.. |image1| image:: https://raw.githubusercontent.com/OCA/contract/19.0/contract/static/src/screenshots/portal-list.png
103+
.. |image2| image:: https://raw.githubusercontent.com/OCA/contract/19.0/contract/static/src/screenshots/portal-detail.png
104104

105105
Known issues / Roadmap
106106
======================
@@ -114,7 +114,7 @@ Bug Tracker
114114
Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_.
115115
In case of trouble, please check there if your issue has already been reported.
116116
If you spotted it first, help us to smash it by providing a detailed and welcomed
117-
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
117+
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20contract%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
118118

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

@@ -158,6 +158,10 @@ Contributors
158158

159159
- Antoni Marroig <amarroig@apsl.net>
160160

161+
- `Heliconia Solutions Pvt. Ltd. <https://www.heliconia.io>`__
162+
163+
- Bhavesh Heliconia
164+
161165
Maintainers
162166
-----------
163167

@@ -171,6 +175,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
171175
mission is to support the collaborative development of Odoo features and
172176
promote its widespread use.
173177

174-
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/18.0/contract>`_ project on GitHub.
178+
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/19.0/contract>`_ project on GitHub.
175179

176180
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

contract/__manifest__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
# Copyright 2020 Tecnativa - Víctor Martínez
1010
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
1111

12+
1213
{
1314
"name": "Recurring - Contracts Management",
14-
"version": "18.0.2.0.6",
15+
"version": "19.0.1.0.0",
1516
"category": "Contract Management",
1617
"license": "AGPL-3",
1718
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",
@@ -29,7 +30,6 @@
2930
"data/template_mail_notification.xml",
3031
"data/mail_message_subtype.xml",
3132
"data/ir_ui_menu.xml",
32-
"wizards/contract_manually_create_invoice.xml",
3333
"views/contract_tag.xml",
3434
"views/contract_template.xml",
3535
"views/contract_template_line.xml",
@@ -38,6 +38,7 @@
3838
"views/res_partner_view.xml",
3939
"views/res_config_settings.xml",
4040
"views/contract_portal_templates.xml",
41+
"wizards/contract_manually_create_invoice.xml",
4142
],
4243
"assets": {
4344
"web.assets_frontend": ["contract/static/src/scss/frontend.scss"],

contract/controllers/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2020-2022 Tecnativa - Víctor Martínez
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import _, http
4+
from odoo import http
55
from odoo.exceptions import AccessError, MissingError
66
from odoo.http import request
77

@@ -50,9 +50,12 @@ def portal_my_contracts(
5050
return request.redirect("/my")
5151
domain = self._get_filter_domain(kw)
5252
searchbar_sortings = {
53-
"date": {"label": _("Date"), "order": "recurring_next_date desc"},
54-
"name": {"label": _("Name"), "order": "name desc"},
55-
"code": {"label": _("Reference"), "order": "code desc"},
53+
"date": {
54+
"label": request.env._("Date"),
55+
"order": "recurring_next_date desc",
56+
},
57+
"name": {"label": request.env._("Name"), "order": "name desc"},
58+
"code": {"label": request.env._("Reference"), "order": "code desc"},
5659
}
5760
# default sort by order
5861
if not sortby:

contract/migrations/18.0.2.0.0/end-migrate.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

contract/migrations/18.0.2.0.0/pre-migrate.py

Lines changed: 0 additions & 94 deletions
This file was deleted.

contract/models/contract.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from odoo import Command, api, fields, models
1515
from odoo.exceptions import ValidationError
16-
from odoo.osv import expression
1716

1817
_logger = logging.getLogger(__name__)
1918

@@ -266,7 +265,6 @@ def _onchange_contract_template_id(self):
266265
(
267266
field.compute,
268267
field.related,
269-
field.automatic,
270268
field.readonly,
271269
field.company_dependent,
272270
field.name in self.NO_SYNC,
@@ -452,7 +450,9 @@ def _get_related_invoices(self):
452450
)
453451
# we are forced to always search for this for not losing possible <=v11
454452
# generated invoices
455-
invoices |= self.env["account.move"].search([("old_contract_id", "=", self.id)])
453+
invoices |= self.env["account.move"].search(
454+
[("old_contract_id", "=", self.ids)]
455+
)
456456
return invoices
457457

458458
def _get_computed_currency(self):
@@ -549,12 +549,11 @@ def _get_contracts_to_invoice_domain(self, date_ref=None):
549549
This method builds the domain to use to find all
550550
contracts (contract.contract) to invoice.
551551
:param date_ref: optional reference date to use instead of today
552-
:return: list (domain) usable on contract.contract
552+
:return: Domain object usable on contract.contract
553553
"""
554-
domain = []
555554
if not date_ref:
556555
date_ref = fields.Date.context_today(self)
557-
domain.extend([("recurring_next_date", "<=", date_ref)])
556+
domain = fields.Domain([("recurring_next_date", "<=", date_ref)])
558557
return domain
559558

560559
def _get_lines_to_invoice(self, date_ref):
@@ -682,7 +681,7 @@ def _cron_recurring_create(self, date_ref=False, create_type="invoice"):
682681
if not date_ref:
683682
date_ref = fields.Date.context_today(self)
684683
domain = self._get_contracts_to_invoice_domain(date_ref)
685-
domain = expression.AND(
684+
domain = fields.Domain.AND(
686685
[
687686
domain,
688687
[("generation_type", "=", create_type)],

contract/models/contract_line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ContractLine(models.Model):
2727
string="Contract",
2828
required=True,
2929
index=True,
30-
auto_join=True,
30+
bypass_search_access=True,
3131
ondelete="cascade",
3232
)
3333
# replace from abstract to add the store=True

contract/models/contract_template_line.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# Copyright 2018 ACSONE SA/NV
77
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
88

9+
import json
10+
911
from odoo import api, fields, models
1012
from odoo.exceptions import ValidationError
1113

@@ -42,18 +44,16 @@ class ContractTemplateLine(models.Model):
4244
readonly=False,
4345
)
4446
quantity = fields.Float(default=1.0, required=True)
45-
product_uom_category_id = fields.Many2one(
46-
comodel_name="uom.category",
47-
related="product_id.uom_id.category_id",
48-
readonly=True,
47+
uom_id_domain = fields.Binary(
48+
compute="_compute_uom_id_domain",
4949
)
5050
uom_id = fields.Many2one(
5151
comodel_name="uom.uom",
5252
compute="_compute_uom_id",
5353
store=True,
5454
readonly=False,
5555
string="Unit of Measure",
56-
domain="[('category_id', '=', product_uom_category_id)]",
56+
domain="uom_id_domain",
5757
)
5858

5959
# === Pricing ===
@@ -153,12 +153,40 @@ def _compute_name(self):
153153
)
154154
line.name = product.get_product_multiline_description_sale()
155155

156-
@api.depends("product_id")
156+
@api.depends("product_id", "product_id.uom_id", "product_id.uom_ids")
157+
def _compute_uom_id_domain(self):
158+
for record in self:
159+
if record.product_id:
160+
allowed_uoms = record.product_id.uom_id | record.product_id.uom_ids
161+
allowed_ids = allowed_uoms.ids
162+
if allowed_ids:
163+
record.uom_id_domain = json.dumps([("id", "in", allowed_ids)])
164+
else:
165+
record.uom_id_domain = json.dumps([("id", "=", False)])
166+
else:
167+
record.uom_id_domain = json.dumps([("id", "=", False)])
168+
169+
@api.depends("product_id", "product_id.uom_id")
157170
def _compute_uom_id(self):
158171
for line in self:
159-
if not line.uom_id or (
160-
line.product_id.uom_id.category_id.id != line.uom_id.category_id.id
161-
):
172+
if not line.product_id:
173+
line.uom_id = False
174+
continue
175+
if line.uom_id_domain:
176+
domain = json.loads(line.uom_id_domain)
177+
allowed_ids = []
178+
for clause in domain:
179+
if isinstance(clause, (list, tuple)) and len(clause) == 3:
180+
if clause[0] == "id" and clause[1] == "in":
181+
allowed_ids = clause[2]
182+
break
183+
if allowed_ids and line.product_id.uom_id.id in allowed_ids:
184+
line.uom_id = line.product_id.uom_id
185+
elif allowed_ids:
186+
line.uom_id = allowed_ids[0]
187+
else:
188+
line.uom_id = False
189+
else:
162190
line.uom_id = line.product_id.uom_id
163191

164192
@api.depends("contract_id.contract_type")

0 commit comments

Comments
 (0)