Skip to content

Commit d97d503

Browse files
committed
[UPD] better readme, copyrights, comments
[IMP] better code and sql constraints [IMP] add tests
1 parent f2790aa commit d97d503

15 files changed

+448
-73
lines changed

.pre-commit-config.yaml

+41-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
4+
^sale_blanket_order_revision/|
45
# END NOT INSTALLABLE ADDONS
56
# Files and folders generated by bots, to avoid loops
67
^setup/|/static/description/index\.html$|
78
# We don't want to mess with tool-generated files
8-
.svg$|/tests/([^/]+/)?cassettes/|
9+
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|
910
# Maybe reactivate this when all README files include prettier ignore tags?
1011
^README\.md$|
1112
# Library files can have extraneous formatting (even minimized)
1213
/static/(src/)?lib/|
1314
# Repos using Sphinx to generate docs don't need prettying
1415
^docs/_templates/.*\.html$|
16+
# Don't bother non-technical authors with formatting issues in docs
17+
readme/.*\.(rst|md)$|
18+
# Ignore build and dist directories in addons
19+
/build/|/dist/|
20+
# Ignore test files in addons
21+
/tests/samples/.*|
1522
# You don't usually want a bot to modify your legal texts
1623
(LICENSE.*|COPYING.*)
1724
default_language_version:
@@ -27,15 +34,33 @@ repos:
2734
entry: found forbidden files; remove them
2835
language: fail
2936
files: "\\.rej$"
37+
- id: en-po-files
38+
name: en.po files cannot exist
39+
entry: found a en.po file
40+
language: fail
41+
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
3042
- repo: https://github.com/oca/maintainer-tools
31-
rev: ab1d7f6
43+
rev: 1b216173c7d11cf682492aefc149f02627068174
3244
hooks:
3345
# update the NOT INSTALLABLE ADDONS section above
3446
- id: oca-update-pre-commit-excluded-addons
3547
- id: oca-fix-manifest-website
3648
args: ["https://github.com/OCA/sale-workflow"]
49+
- id: oca-gen-addon-readme
50+
args:
51+
- --addons-dir=.
52+
- --branch=14.0
53+
- --org-name=OCA
54+
- --repo-name=sale-workflow
55+
- --if-source-changed
56+
- --keep-source-digest
57+
- repo: https://github.com/OCA/odoo-pre-commit-hooks
58+
rev: v0.0.31
59+
hooks:
60+
- id: oca-checks-odoo-module
61+
- id: oca-checks-po
3762
- repo: https://github.com/myint/autoflake
38-
rev: v1.4
63+
rev: v2.3.1
3964
hooks:
4065
- id: autoflake
4166
args:
@@ -46,11 +71,11 @@ repos:
4671
- --remove-duplicate-keys
4772
- --remove-unused-variables
4873
- repo: https://github.com/psf/black
49-
rev: 20.8b1
74+
rev: 24.4.2
5075
hooks:
5176
- id: black
5277
- repo: https://github.com/pre-commit/mirrors-prettier
53-
rev: v2.1.2
78+
rev: v4.0.0-alpha.8
5479
hooks:
5580
- id: prettier
5681
name: prettier (with plugin-xml)
@@ -61,15 +86,15 @@ repos:
6186
- --plugin=@prettier/plugin-xml
6287
files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$
6388
- repo: https://github.com/pre-commit/mirrors-eslint
64-
rev: v7.8.1
89+
rev: v9.8.0
6590
hooks:
6691
- id: eslint
6792
verbose: true
6893
args:
6994
- --color
7095
- --fix
7196
- repo: https://github.com/pre-commit/pre-commit-hooks
72-
rev: v3.2.0
97+
rev: v4.6.0
7398
hooks:
7499
- id: trailing-whitespace
75100
# exclude autogenerated files
@@ -91,20 +116,20 @@ repos:
91116
- id: mixed-line-ending
92117
args: ["--fix=lf"]
93118
- repo: https://github.com/asottile/pyupgrade
94-
rev: v2.7.2
119+
rev: v3.17.0
95120
hooks:
96121
- id: pyupgrade
97122
args: ["--keep-percent-format"]
98123
- repo: https://github.com/PyCQA/isort
99-
rev: 5.5.1
124+
rev: 5.13.2
100125
hooks:
101126
- id: isort
102127
name: isort except __init__.py
103128
args:
104129
- --settings=.
105130
exclude: /__init__\.py$
106131
- repo: https://github.com/acsone/setuptools-odoo
107-
rev: 2.6.0
132+
rev: "3.3"
108133
hooks:
109134
- id: setuptools-odoo-make-default
110135
- id: setuptools-odoo-get-requirements
@@ -113,25 +138,21 @@ repos:
113138
- requirements.txt
114139
- --header
115140
- "# generated from manifests external_dependencies"
116-
- repo: https://gitlab.com/PyCQA/flake8
117-
rev: 3.8.3
141+
- repo: https://github.com/PyCQA/flake8
142+
rev: 7.1.0
118143
hooks:
119144
- id: flake8
120145
name: flake8
121146
additional_dependencies: ["flake8-bugbear==20.1.4"]
122-
- repo: https://github.com/PyCQA/pylint
123-
rev: pylint-2.5.3
147+
- repo: https://github.com/OCA/pylint-odoo
148+
rev: v9.1.2
124149
hooks:
125-
- id: pylint
150+
- id: pylint_odoo
126151
name: pylint with optional checks
127152
args:
128153
- --rcfile=.pylintrc
129154
- --exit-zero
130155
verbose: true
131-
additional_dependencies: &pylint_deps
132-
- pylint-odoo==3.5.0
133-
- id: pylint
134-
name: pylint with mandatory checks
156+
- id: pylint_odoo
135157
args:
136158
- --rcfile=.pylintrc-mandatory
137-
additional_dependencies: *pylint_deps

sale_partner_primeship/README.rst

+19-11
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22
Sale Partner Primeship
33
======================
44

5-
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67
!! This file is generated by oca-gen-addon-readme !!
78
!! changes will be overwritten. !!
89
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:4a8b2bd09f624001cb742f00bfe88a35f7c7ba7dceca566dae0bb4ed0d49e56e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
912
1013
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1114
:target: https://odoo-community.org/page/development-status
1215
:alt: Beta
13-
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
14-
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
15-
:alt: License: LGPL-3
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
1619
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
1720
:target: https://github.com/OCA/sale-workflow/tree/14.0/sale_partner_primeship
1821
:alt: OCA/sale-workflow
1922
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
2023
:target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_partner_primeship
2124
:alt: Translate me on Weblate
22-
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/167/14.0
24-
:alt: Try me on Runbot
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=14.0
27+
:alt: Try me on Runboat
2528

26-
|badge1| |badge2| |badge3| |badge4| |badge5|
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
2730

2831
This module adds a concept of primeship for partners.
32+
A primeship is basically a simple membership very easy to use.
2933
This primeship is activated on the confirmation of a sale containing
30-
a primeship activation product for a customizable duration.
34+
a primeship activation product for a customizable duration expressed in months.
35+
It is automatically deactivated when the duration expires.
36+
You can then check if the primeship is active for a particular customer
37+
and take actions based on it.
3138

3239
**Table of contents**
3340

@@ -44,7 +51,7 @@ go to the product form Sales tab and tick the Activates primeship checkbox:
4451

4552
You can then set a primeship duration.
4653

47-
You can see current primeship availability for a customer:
54+
You can see current primeship availability for a customer:
4855

4956
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/14.0/sale_partner_primeship/static/description/partner-with-primeship.png
5057

@@ -57,7 +64,7 @@ Bug Tracker
5764

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

6370
Do not contact contributors directly about support or help with technical issues.
@@ -76,6 +83,7 @@ Contributors
7683
* `Akretion <https://www.akretion.com>`_:
7784

7885
* Florian Mounier
86+
* Kevin Roche
7987
* Olivier Nibart
8088

8189
Maintainers

sale_partner_primeship/__manifest__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2021 Akretion - Florian Mounier
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
23
{
34
"name": "Sale Partner Primeship",
45
"summary": """Allow you to manage time limited prime memberships
@@ -16,5 +17,5 @@
1617
"security/sale_partner_primeship.xml",
1718
"data/ir_cron.xml",
1819
],
19-
"license": "LGPL-3",
20+
"license": "AGPL-3",
2021
}

sale_partner_primeship/models/product_template.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright 2021 Akretion France (http://www.akretion.com/)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
14
from odoo import fields, models
25

36

sale_partner_primeship/models/res_partner.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2021 Akretion France (http://www.akretion.com/)
2+
# Copyright 2023 Akretion France (http://www.akretion.com/)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
15
from odoo import api, fields, models
26

37

@@ -10,8 +14,13 @@ class ResPartner(models.Model):
1014
required=True,
1115
)
1216

17+
# store True allow to filter on active_primeship.
18+
# There is a cron job to set it to False when the customer has no active
19+
# primeship anymore.
1320
active_primeship = fields.Boolean(
14-
string="Active Primeship", compute="_compute_active_primeship", store=True
21+
string="Active Primeship",
22+
compute="_compute_active_primeship",
23+
store=True,
1524
)
1625
primeship_count = fields.Integer(
1726
string="Primeships Count", compute="_compute_primeship_count"

sale_partner_primeship/models/sale_order.py

+35-18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2021 Akretion France (http://www.akretion.com/)
2+
# Copyright 2024 Akretion France (http://www.akretion.com/)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
15
from dateutil.relativedelta import relativedelta
26

37
from odoo import api, fields, models
@@ -6,8 +10,9 @@
610
class SaleOrder(models.Model):
711
_inherit = "sale.order"
812

9-
def action_confirm(self):
10-
rv = super().action_confirm()
13+
def _action_confirm(self):
14+
super()._action_confirm()
15+
sale_primeship = self.env["sale.primeship"]
1116
for record in self:
1217
partner = record.partner_id.commercial_partner_id
1318

@@ -28,22 +33,35 @@ def action_confirm(self):
2833
start = primeship.end_date
2934
end = start + relativedelta(months=duration)
3035

31-
self.env["sale.primeship"].create(
32-
{
33-
"start_date": start,
34-
"end_date": end,
35-
"partner_id": partner.id,
36-
"order_line_id": line.id,
37-
}
38-
)
39-
return rv
36+
vals = {
37+
"start_date": start,
38+
"end_date": end,
39+
"partner_id": partner.id,
40+
"order_line_id": line.id,
41+
# this is to reactivate a maybe deactivated existing primeship
42+
"active": True,
43+
}
44+
if line.primeship_id:
45+
# Hm... something seems to have gone wrong here,
46+
# but we handle it nonetheless.
47+
line.primeship_id.write(vals)
48+
else:
49+
# We may have a deactivated primeship because of an order
50+
# cancellation.
51+
primeship = sale_primeship.with_context(
52+
active_test=False,
53+
).search([("order_line_id", "=", line.id)])
54+
if primeship:
55+
primeship.write(vals)
56+
else:
57+
sale_primeship.create(vals)
58+
59+
return True
4060

4161
def action_cancel(self):
4262
rv = super().action_cancel()
43-
4463
for record in self:
4564
record.order_line.mapped("primeship_id").active = False
46-
4765
return rv
4866

4967

@@ -65,8 +83,7 @@ class SaleOrderLine(models.Model):
6583
@api.depends("primeship_ids")
6684
def _compute_primeship_id(self):
6785
for record in self:
68-
if record.primeship_ids:
69-
record.primeship_id = record.primeship_ids[0]
86+
record.primeship_id = record.primeship_ids[:1]
7087

7188
def _inverse_primeship_id(self):
7289
for record in self:
@@ -78,10 +95,10 @@ def _inverse_primeship_id(self):
7895

7996
record.primeship_id.order_line_id = record
8097

81-
# Update invoice start/end dates
8298
def _prepare_invoice_line(self, **optional_values):
83-
# Set invoice start/end dates to primeship start/end dates
84-
# In case of multi quantity, this assumes continuous date ranges
99+
"""Update invoice start/end dates.
100+
Set invoice start/end dates to primeship start/end dates
101+
In case of multi quantity, this assumes continuous date ranges."""
85102
self.ensure_one()
86103
res = super()._prepare_invoice_line(**optional_values)
87104
if self.primeship_id:

sale_partner_primeship/models/sale_primeship.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright 2021 Akretion France (http://www.akretion.com/)
2+
# Copyright 2024 Akretion France (http://www.akretion.com/)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
4+
15
from odoo import _, api, fields, models
26
from odoo.exceptions import ValidationError
37

@@ -19,16 +23,23 @@ class SalePrimeship(models.Model):
1923
ondelete="cascade",
2024
index=True,
2125
)
22-
2326
order_line_id = fields.Many2one(
2427
comodel_name="sale.order.line",
2528
string="Sale Order Line",
2629
)
27-
2830
order_id = fields.Many2one(string="Sale Order", related="order_line_id.order_id")
2931

3032
current = fields.Boolean(string="Currently Active", compute="_compute_current")
3133

34+
_sql_constraints = [
35+
# Constraint for One2one impl of "sale.order.line".primeship_id
36+
(
37+
"unique_order_line",
38+
"UNIQUE(order_line_id)",
39+
"A sale order line can only have one primeship!",
40+
)
41+
]
42+
3243
@api.depends("start_date", "end_date")
3344
def _compute_name(self):
3445
for record in self:
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
* `Akretion <https://www.akretion.com>`_:
22

33
* Florian Mounier
4+
* Kevin Roche
5+
* Olivier Nibart

0 commit comments

Comments
 (0)