From 9d1ae5c10078e826e01d709598aa82cadb8d5deb Mon Sep 17 00:00:00 2001
From: Dave Lasley
Date: Fri, 5 May 2017 13:43:25 -0700
Subject: [PATCH] [ADD] contract_auto: Automatic Payment For Contracts
---
.travis.yml | 14 +-
contract_payment_auto/README.rst | 89 +++++
contract_payment_auto/__init__.py | 5 +
contract_payment_auto/__manifest__.py | 27 ++
contract_payment_auto/data/ir_cron_data.xml | 19 ++
.../data/mail_template_data.xml | 98 ++++++
contract_payment_auto/models/__init__.py | 8 +
.../models/account_analytic_account.py | 174 ++++++++++
.../models/account_analytic_contract.py | 108 +++++++
.../models/account_invoice.py | 12 +
contract_payment_auto/models/res_partner.py | 18 ++
contract_payment_auto/tests/__init__.py | 6 +
.../tests/test_account_analytic_account.py | 303 ++++++++++++++++++
.../tests/test_account_analytic_contract.py | 51 +++
.../views/account_analytic_account_view.xml | 44 +++
.../views/account_analytic_contract_view.xml | 36 +++
.../views/res_partner_view.xml | 22 ++
17 files changed, 1027 insertions(+), 7 deletions(-)
create mode 100644 contract_payment_auto/README.rst
create mode 100644 contract_payment_auto/__init__.py
create mode 100644 contract_payment_auto/__manifest__.py
create mode 100644 contract_payment_auto/data/ir_cron_data.xml
create mode 100644 contract_payment_auto/data/mail_template_data.xml
create mode 100644 contract_payment_auto/models/__init__.py
create mode 100644 contract_payment_auto/models/account_analytic_account.py
create mode 100644 contract_payment_auto/models/account_analytic_contract.py
create mode 100644 contract_payment_auto/models/account_invoice.py
create mode 100644 contract_payment_auto/models/res_partner.py
create mode 100644 contract_payment_auto/tests/__init__.py
create mode 100644 contract_payment_auto/tests/test_account_analytic_account.py
create mode 100644 contract_payment_auto/tests/test_account_analytic_contract.py
create mode 100644 contract_payment_auto/views/account_analytic_account_view.xml
create mode 100644 contract_payment_auto/views/account_analytic_contract_view.xml
create mode 100644 contract_payment_auto/views/res_partner_view.xml
diff --git a/.travis.yml b/.travis.yml
index 795d0d93..aa47c437 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,26 +7,26 @@ python:
addons:
apt:
-# only add the two lines below if you need wkhtmltopdf for your tests
-# sources:
-# - pov-wkhtmltopdf
+ sources:
+ - pov-wkhtmltopdf
packages:
- expect-dev # provides unbuffer utility
- python-lxml # because pip installation is slow
- python-simplejson
- python-serial
- python-yaml
-# - wkhtmltopdf # only add if needed and check the before_install section below
+ - wkhtmltopdf
# set up an X server to run wkhtmltopdf.
-#before_install:
-# - "export DISPLAY=:910.0"
-# - "sh -e /etc/init.d/xvfb start"
+before_install:
+ - "export DISPLAY=:910.0"
+ - "sh -e /etc/init.d/xvfb start"
env:
global:
- VERSION="10.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- TRANSIFEX_USER='transbot@odoo-community.org'
+ - WKHTMLTOPDF_VERSION="0.12.4"
- secure: ArnbVaF5+ry6zVysZ7HA9xcnQrodo8FsXXcon9yINTYRfDC9QEr+/mTLAPRl+lVLdtWV2GuGuX0vPYzBxFWpY3LR0BpKqXzx0G51s94zR2WWEmizYFzFhpAuIxoU4CYNckHFSUaPAQJhwB/pYx9+H/W6bMjG/VnZBq+AmBJ2Kh0=
matrix:
diff --git a/contract_payment_auto/README.rst b/contract_payment_auto/README.rst
new file mode 100644
index 00000000..160757bf
--- /dev/null
+++ b/contract_payment_auto/README.rst
@@ -0,0 +1,89 @@
+.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+ :alt: License: AGPL-3
+
+=====================
+Contract Auto Payment
+=====================
+
+This module allows for the configuration of automatic payments on invoices that are created by a contract.
+
+Usage
+=====
+
+Enable Automatic Payment
+------------------------
+
+* Navigate to a customer contract
+* Check the `Auto Pay?` box to enable automatic payment
+* Configure the options as desired
+* Set the `Payment Token` to the payment token that should be used for automatic payment
+
+Automatic Payment Settings
+--------------------------
+
+The following settings are available at both the contract and contract template level:
+
+| Name | Description |
+|------|-------------|
+| Invoice Message | Message template that is used to send invoices to customers upon creation. |
+| Payment Retry Message | Message template that is used to alert a customer that their automatic payment failed for some reason and will be retried. |
+| Payment Fail Message | Message template that is used to alert a customer that their automatic payment failed and will no longer be retried. |
+| Auto Pay Retries | Amount of times to attempt an automatic payment before discontinuing and removing the payment token from the contract/account payment method. |
+| Auto Pay Retry Hours | Amount of hours that should lapse until retrying failed payments. |
+
+Payment Token
+-------------
+
+A valid payment token is required to use this module. These tokens are typically created during the `website_sale` checkout process, but they can also be created manually at the acquirer.
+
+A payment token can be defined in one of two areas:
+
+* Contract - Defining a payment token in the contract will allow for the use of this token for automatic payments on this contract only.
+* Partner - Defining a payment token in the partner will allow for the use of this token for automatic payments on all contracts for this partner that do not have a payment token defined.
+
+.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
+ :alt: Try me on Runbot
+ :target: https://runbot.odoo-community.org/runbot/110/10.0
+
+Known issues / Roadmap
+======================
+
+* None
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues
+`_. In case of trouble, please
+check there if your issue has already been reported. If you spotted it first,
+help us smash it by providing detailed and welcomed feedback.
+
+Credits
+=======
+
+Images
+------
+
+* Odoo Community Association: `Icon `_.
+
+Contributors
+------------
+
+* Dave Lasley
+
+
+Maintainer
+----------
+
+.. image:: https://odoo-community.org/logo.png
+ :alt: Odoo Community Association
+ :target: https://odoo-community.org
+
+This module is maintained by the OCA.
+
+OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.
+
+To contribute to this module, please visit https://odoo-community.org.
diff --git a/contract_payment_auto/__init__.py b/contract_payment_auto/__init__.py
new file mode 100644
index 00000000..44db863b
--- /dev/null
+++ b/contract_payment_auto/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Copyright 2017 LasLabs Inc.
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from . import models
diff --git a/contract_payment_auto/__manifest__.py b/contract_payment_auto/__manifest__.py
new file mode 100644
index 00000000..0efcab79
--- /dev/null
+++ b/contract_payment_auto/__manifest__.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# Copyright 2017 LasLabs Inc.
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+{
+ "name": "Contract - Auto Payment",
+ "summary": "Adds automatic payments to contracts.",
+ "version": "10.0.1.0.0",
+ "category": "Contract Management",
+ "license": "AGPL-3",
+ "author": "LasLabs, "
+ "Odoo Community Association (OCA)",
+ "website": "https://laslabs.com",
+ "depends": [
+ "contract",
+ "payment",
+ ],
+ "data": [
+ "data/mail_template_data.xml",
+ "data/ir_cron_data.xml",
+ "views/account_analytic_account_view.xml",
+ "views/account_analytic_contract_view.xml",
+ "views/res_partner_view.xml",
+ ],
+ "installable": True,
+ "application": False,
+}
diff --git a/contract_payment_auto/data/ir_cron_data.xml b/contract_payment_auto/data/ir_cron_data.xml
new file mode 100644
index 00000000..5e51ad8c
--- /dev/null
+++ b/contract_payment_auto/data/ir_cron_data.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+ Contract Automatic Payments
+ hours
+ 1
+ account.analytic.account
+ cron_retry_auto_pay
+ ()
+
+
+
diff --git a/contract_payment_auto/data/mail_template_data.xml b/contract_payment_auto/data/mail_template_data.xml
new file mode 100644
index 00000000..3f8fc004
--- /dev/null
+++ b/contract_payment_auto/data/mail_template_data.xml
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+ Invoice - AutoPay To Retry
+ ${(object.user_id.email and '%s <%s>' % (object.user_id.name, object.user_id.email) or '')|safe}
+ Automatic Payment Failure (Ref ${object.number or 'n/a'})
+ ${object.partner_id.id}
+
+
+
+ Invoice_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}
+ ${object.partner_id.lang}
+
+ Hello ${object.partner_id.name}
+ % set access_action = object.get_access_action()
+ % set access_url = access_action['type'] == 'ir.actions.act_url' and access_action['url'] or '/report/pdf/account.report_invoice/' + str(object.id)
+ % if object.partner_id.parent_id:
+ (${object.partner_id.parent_id.name})
+ % endif
+ ,
+