Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions subscription_oca/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=======================
Subscription management
=======================
Expand All @@ -17,7 +13,7 @@ Subscription management
.. |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/license-AGPL--3-blue.png
.. |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%2Fcontract-lightgray.png?logo=github
Expand Down Expand Up @@ -91,6 +87,13 @@ Contributors

* Ilyas <irazor147@gmail.com>


* `Binhex <https://binhex.cloud>`__:

* Adasat Torres de Leon <a.torres@binhex.cloud>

* Chris Mann <chrisandrewmann>

Maintainers
~~~~~~~~~~~

Expand Down
92 changes: 90 additions & 2 deletions subscription_oca/models/sale_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ class SaleSubscription(models.Model):
store=True,
ondelete="restrict",
)
payment_token_id = fields.Many2one(
comodel_name="payment.token",
string="Payment Token",
store=True,
compute="_compute_payment_token_id",
domain="[('partner_id', '=', partner_id)]",
)
invoicing_mode = fields.Selection(related="template_id.invoicing_mode")

@api.depends("partner_id", "template_id")
def _compute_payment_token_id(self):
for record in self:
if record.template_id.invoicing_mode not in [
"invoice_and_payment",
]:
record.payment_token_id = False
continue
payment_token = (
self.env["payment.token"]
.sudo()
.with_company(record.company_id)
.search(
[
("partner_id", "=", record.partner_id.id),
],
limit=1,
order="write_date desc",
)
)
record.payment_token_id = payment_token.id if payment_token else False

@api.model
def _read_group_stage_ids(self, stages, domain, order):
Expand Down Expand Up @@ -328,11 +358,21 @@ def create_sale_order(self):
def generate_invoice(self):
invoice_number = ""
msg_static = _("Created invoice with reference")
if self.template_id.invoicing_mode in ["draft", "invoice", "invoice_send"]:
if self.template_id.invoicing_mode in [
"draft",
"invoice",
"invoice_send",
"invoice_and_payment",
]:
invoice = self.create_invoice()
if self.template_id.invoicing_mode != "draft":
invoice.action_post()
if self.template_id.invoicing_mode == "invoice_send":
if self.template_id.invoicing_mode == "invoice_and_payment":
self.create_payment(invoice)
if self.template_id.invoicing_mode in (
"invoice_send",
"invoice_and_payment",
):
mail_template = self.template_id.invoice_mail_template_id
invoice.with_context(force_send=True).message_post_with_template(
mail_template.id,
Expand Down Expand Up @@ -363,6 +403,54 @@ def generate_invoice(self):
self.calculate_recurring_next_date(self.recurring_next_date)
self.message_post(body=message_body)

def create_payment(self, invoice):
invoice.ensure_one()
if not self.payment_token_id:
self.message_post(
body=_(
"No payment token found for partner %s" % invoice.partner_id.name
)
)
return
provider = self.payment_token_id.provider_id
method_line = self.env["account.payment.method.line"].search(
[
("payment_method_id.code", "=", provider.code),
("company_id", "=", invoice.company_id.id),
],
limit=1,
)

if not method_line:
self.message_post(
body=_(
"No payment method line found for payment provider %s"
% provider.name
)
)
return
payment_register = self.env["account.payment.register"]
payment_vals = {
"currency_id": invoice.currency_id.id,
"journal_id": provider.journal_id.id,
"company_id": invoice.company_id.id,
"partner_id": invoice.partner_id.id,
"communication": invoice.name,
"payment_type": "inbound",
"partner_type": "customer",
"payment_difference_handling": "open",
"writeoff_label": "Write-Off",
"payment_date": fields.Date.today(),
"amount": invoice.amount_total,
"payment_method_line_id": method_line.id,
"payment_token_id": self.payment_token_id.id,
}
payment_register.with_context(
active_model="account.move",
active_ids=invoice.ids,
active_id=invoice.id,
).create(payment_vals).action_create_payments()

def manual_invoice(self):
invoice_id = self.create_invoice()
self.calculate_recurring_next_date(self.recurring_next_date)
Expand Down
1 change: 1 addition & 0 deletions subscription_oca/models/sale_subscription_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SaleSubscriptionTemplate(models.Model):
("invoice", "Invoice"),
("invoice_send", "Invoice & send"),
("sale_and_invoice", "Sale order & Invoice"),
("invoice_and_payment", "Invoice & Recurring Payment"),
],
)
code = fields.Char()
Expand Down
7 changes: 7 additions & 0 deletions subscription_oca/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
* `Ooops404 <https://www.ooops404.com>`__:

* Ilyas <irazor147@gmail.com>


* `Binhex <https://binhex.cloud>`__:

* Adasat Torres de Leon <a.torres@binhex.cloud>

* Chris Mann <chrisandrewmann>
33 changes: 16 additions & 17 deletions subscription_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Subscription management</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="subscription-management">
<h1 class="title">Subscription management</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="subscription-management">
<h1>Subscription management</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0f74e3f2d1fce7423f268d9e6d62b9e9fe3af4629ec13a22c42fe64660c74bfe
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/16.0/subscription_oca"><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-subscription_oca"><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><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/subscription_oca"><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-subscription_oca"><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 allows creating subscriptions that generate recurring invoices or orders. It also enables the sale of products that generate subscriptions.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -391,7 +386,7 @@ <h1>Subscription management</h1>
</ul>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To make a subscription:</p>
<ol class="arabic simple">
<li>Go to <em>Subscriptions &gt; Configuration &gt; Subscription templates</em>.</li>
Expand All @@ -408,41 +403,46 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Refactor all the onchanges that have business logic to computed write-able fields when possible. Keep onchanges only for UI purposes.</li>
<li>Add tests.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<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.
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:%20subscription_oca%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>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>Domatix</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Carlos Martínez &lt;<a class="reference external" href="mailto:carlos&#64;domatix.com">carlos&#64;domatix.com</a>&gt;</li>
<li>Carolina Ferrer &lt;<a class="reference external" href="mailto:carolina&#64;domatix.com">carolina&#64;domatix.com</a>&gt;</li>
<li><a class="reference external" href="https://www.ooops404.com">Ooops404</a>:<ul>
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://binhex.cloud">Binhex</a>:<ul>
<li>Adasat Torres de Leon &lt;<a class="reference external" href="mailto:a.torres&#64;binhex.cloud">a.torres&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
<li>Chris Mann &lt;chrisandrewmann&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">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" />
Expand All @@ -455,6 +455,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
Loading