Skip to content

Commit

Permalink
[UPD] better readme, copyrights, comments
Browse files Browse the repository at this point in the history
[IMP] better code and sql constraints

[IMP] add tests
  • Loading branch information
nayatec committed Jul 30, 2024
1 parent f2790aa commit da53c46
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 53 deletions.
30 changes: 19 additions & 11 deletions sale_partner_primeship/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,39 @@
Sale Partner Primeship
======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4a8b2bd09f624001cb742f00bfe88a35f7c7ba7dceca566dae0bb4ed0d49e56e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/14.0/sale_partner_primeship
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_partner_primeship
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/14.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=14.0
:alt: Try me on Runboat

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

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

**Table of contents**

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

You can then set a primeship duration.

You can see current primeship availability for a customer:
You can see current primeship availability for a customer:

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

Expand All @@ -57,7 +64,7 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing 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/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**>`_.

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

* Florian Mounier
* Kevin Roche
* Olivier Nibart

Maintainers
Expand Down
3 changes: 2 additions & 1 deletion sale_partner_primeship/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2021 Akretion - Florian Mounier
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sale Partner Primeship",
"summary": """Allow you to manage time limited prime memberships
Expand All @@ -16,5 +17,5 @@
"security/sale_partner_primeship.xml",
"data/ir_cron.xml",
],
"license": "LGPL-3",
"license": "AGPL-3",
}
3 changes: 3 additions & 0 deletions sale_partner_primeship/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


Expand Down
11 changes: 10 additions & 1 deletion sale_partner_primeship/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# Copyright 2023 Akretion France (http://www.akretion.com/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


Expand All @@ -10,8 +14,13 @@ class ResPartner(models.Model):
required=True,
)

# store True allow to filter on active_primeship.
# There is a cron job to set it to False when the customer has no active
# primeship anymore.
active_primeship = fields.Boolean(
string="Active Primeship", compute="_compute_active_primeship", store=True
string="Active Primeship",
compute="_compute_active_primeship",
store=True,
)
primeship_count = fields.Integer(
string="Primeships Count", compute="_compute_primeship_count"
Expand Down
53 changes: 35 additions & 18 deletions sale_partner_primeship/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# Copyright 2024 Akretion France (http://www.akretion.com/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from dateutil.relativedelta import relativedelta

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

def action_confirm(self):
rv = super().action_confirm()
def _action_confirm(self):
super()._action_confirm()
sale_primeship = self.env["sale.primeship"]
for record in self:
partner = record.partner_id.commercial_partner_id

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

self.env["sale.primeship"].create(
{
"start_date": start,
"end_date": end,
"partner_id": partner.id,
"order_line_id": line.id,
}
)
return rv
vals = {
"start_date": start,
"end_date": end,
"partner_id": partner.id,
"order_line_id": line.id,
# this is to reactivate a maybe deactivated existing primeship
"active": True,
}
if line.primeship_id:
# Hm... something seems to have gone wrong here,
# but we handle it nonetheless.
line.primeship_id.write(vals)
else:
# We may have a deactivated primeship because of an order
# cancellation.
primeship = sale_primeship.with_context(
active_test=False,
).search([("order_line_id", "=", line.id)])
if primeship:
primeship.write(vals)
else:
sale_primeship.create(vals)

return True

def action_cancel(self):
rv = super().action_cancel()

for record in self:
record.order_line.mapped("primeship_id").active = False

return rv


Expand All @@ -65,8 +83,7 @@ class SaleOrderLine(models.Model):
@api.depends("primeship_ids")
def _compute_primeship_id(self):
for record in self:
if record.primeship_ids:
record.primeship_id = record.primeship_ids[0]
record.primeship_id = record.primeship_ids[:1]

def _inverse_primeship_id(self):
for record in self:
Expand All @@ -78,10 +95,10 @@ def _inverse_primeship_id(self):

record.primeship_id.order_line_id = record

# Update invoice start/end dates
def _prepare_invoice_line(self, **optional_values):
# Set invoice start/end dates to primeship start/end dates
# In case of multi quantity, this assumes continuous date ranges
"""Update invoice start/end dates.
Set invoice start/end dates to primeship start/end dates
In case of multi quantity, this assumes continuous date ranges."""
self.ensure_one()
res = super()._prepare_invoice_line(**optional_values)
if self.primeship_id:
Expand Down
15 changes: 13 additions & 2 deletions sale_partner_primeship/models/sale_primeship.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# Copyright 2024 Akretion France (http://www.akretion.com/)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

Expand All @@ -19,16 +23,23 @@ class SalePrimeship(models.Model):
ondelete="cascade",
index=True,
)

order_line_id = fields.Many2one(
comodel_name="sale.order.line",
string="Sale Order Line",
)

order_id = fields.Many2one(string="Sale Order", related="order_line_id.order_id")

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

_sql_constraints = [
# Constraint for One2one impl of "sale.order.line".primeship_id
(
"unique_order_line",
"UNIQUE(order_line_id)",
"A sale order line can only have one primeship!",
)
]

@api.depends("start_date", "end_date")
def _compute_name(self):
for record in self:
Expand Down
2 changes: 2 additions & 0 deletions sale_partner_primeship/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* `Akretion <https://www.akretion.com>`_:

* Florian Mounier
* Kevin Roche
* Olivier Nibart
6 changes: 5 additions & 1 deletion sale_partner_primeship/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
This module adds a concept of primeship for partners.
A primeship is basically a simple membership very easy to use.
This primeship is activated on the confirmation of a sale containing
a primeship activation product for a customizable duration.
a primeship activation product for a customizable duration expressed in months.
It is automatically deactivated when the duration expires.
You can then check if the primeship is active for a particular customer
and take actions based on it.
46 changes: 27 additions & 19 deletions sale_partner_primeship/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?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">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Sale Partner Primeship</title>
<style type="text/css">

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

Expand Down Expand Up @@ -366,26 +366,32 @@ <h1 class="title">Sale Partner Primeship</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4a8b2bd09f624001cb742f00bfe88a35f7c7ba7dceca566dae0bb4ed0d49e56e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>
<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>
<p>This module adds a concept of primeship for partners.
A primeship is basically a simple membership very easy to use.
This primeship is activated on the confirmation of a sale containing
a primeship activation product for a customizable duration.</p>
a primeship activation product for a customizable duration expressed in months.
It is automatically deactivated when the duration expires.
You can then check if the primeship is active for a particular customer
and take actions based on it.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To make a product that activates primeship on sale order, you have to edit it, set its type to service and
go to the product form Sales tab and tick the Activates primeship checkbox:</p>
<div class="figure">
Expand All @@ -402,32 +408,34 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing 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/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>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Akretion</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.akretion.com">Akretion</a>:<ul>
<li>Florian Mounier</li>
<li>Kevin Roche</li>
<li>Olivier Nibart</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
6 changes: 6 additions & 0 deletions sale_partner_primeship/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2024 Akretion - Olivier Nibart
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_res_partner_primeship
from . import test_sale_order_primeship
from . import test_sale_primeship
Loading

0 comments on commit da53c46

Please sign in to comment.