Skip to content

Commit da53c46

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

14 files changed

+407
-53
lines changed

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
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
This module adds a concept of primeship for partners.
2+
A primeship is basically a simple membership very easy to use.
23
This primeship is activated on the confirmation of a sale containing
3-
a primeship activation product for a customizable duration.
4+
a primeship activation product for a customizable duration expressed in months.
5+
It is automatically deactivated when the duration expires.
6+
You can then check if the primeship is active for a particular customer
7+
and take actions based on it.

sale_partner_primeship/static/description/index.html

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
6+
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
77
<title>Sale Partner Primeship</title>
88
<style type="text/css">
99

1010
/*
1111
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
12+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1313
:Copyright: This stylesheet has been placed in the public domain.
1414
1515
Default cascading style sheet for the HTML output of Docutils.
1616
17-
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
17+
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
1919
*/
2020

@@ -366,26 +366,32 @@ <h1 class="title">Sale Partner Primeship</h1>
366366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370+
!! source digest: sha256:4a8b2bd09f624001cb742f00bfe88a35f7c7ba7dceca566dae0bb4ed0d49e56e
369371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" 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" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/14.0/sale_partner_primeship"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_partner_primeship"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/167/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
372+
<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/sale-workflow/tree/14.0/sale_partner_primeship"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_partner_primeship"><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/sale-workflow&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
371373
<p>This module adds a concept of primeship for partners.
374+
A primeship is basically a simple membership very easy to use.
372375
This primeship is activated on the confirmation of a sale containing
373-
a primeship activation product for a customizable duration.</p>
376+
a primeship activation product for a customizable duration expressed in months.
377+
It is automatically deactivated when the duration expires.
378+
You can then check if the primeship is active for a particular customer
379+
and take actions based on it.</p>
374380
<p><strong>Table of contents</strong></p>
375381
<div class="contents local topic" id="contents">
376382
<ul class="simple">
377-
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
378-
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
379-
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
380-
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
381-
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
382-
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
383+
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
384+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
385+
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
386+
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
387+
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
388+
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
383389
</ul>
384390
</li>
385391
</ul>
386392
</div>
387393
<div class="section" id="usage">
388-
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
394+
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
389395
<p>To make a product that activates primeship on sale order, you have to edit it, set its type to service and
390396
go to the product form Sales tab and tick the Activates primeship checkbox:</p>
391397
<div class="figure">
@@ -402,32 +408,34 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
402408
</div>
403409
</div>
404410
<div class="section" id="bug-tracker">
405-
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
411+
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
406412
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/issues">GitHub Issues</a>.
407413
In case of trouble, please check there if your issue has already been reported.
408-
If you spotted it first, help us smashing it by providing a detailed and welcomed
414+
If you spotted it first, help us to smash it by providing a detailed and welcomed
409415
<a class="reference external" href="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**">feedback</a>.</p>
410416
<p>Do not contact contributors directly about support or help with technical issues.</p>
411417
</div>
412418
<div class="section" id="credits">
413-
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
419+
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
414420
<div class="section" id="authors">
415-
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
421+
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
416422
<ul class="simple">
417423
<li>Akretion</li>
418424
</ul>
419425
</div>
420426
<div class="section" id="contributors">
421-
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
427+
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
422428
<ul class="simple">
423429
<li><a class="reference external" href="https://www.akretion.com">Akretion</a>:<ul>
424430
<li>Florian Mounier</li>
431+
<li>Kevin Roche</li>
432+
<li>Olivier Nibart</li>
425433
</ul>
426434
</li>
427435
</ul>
428436
</div>
429437
<div class="section" id="maintainers">
430-
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
438+
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
431439
<p>This module is maintained by the OCA.</p>
432440
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
433441
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2024 Akretion - Olivier Nibart
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from . import test_res_partner_primeship
5+
from . import test_sale_order_primeship
6+
from . import test_sale_primeship

0 commit comments

Comments
 (0)