Commit 48b535f2 authored by Patrik Dufresne's avatar Patrik Dufresne

Revert "Remove membership_variable_period."

This reverts commit 3bc97481.
parent 3bc97481
===============================
Variable period for memberships
===============================
Current membership module allows to set products that define a fixed period
for a membership. This is good when the quotas are defined periodically, and
when you become a member, you are until the end of that quota cycle.
But a lot of times, membership quotas express an amount of time that you
gain the membership. For example, one year since the subscription.
This module allows to make it in Odoo, using current membership features,
and adapting them for this purpose. As now the quota is not attached to a fixed
period, you can also invoice more than one quantity for being a member for
the corresponding number of periods.
Finally, a cron has been included that triggers the recalculation of the
membership state, allowing to have "old members", which doesn't work well
on standard.
Usage
=====
Define a member product, and select 'Variable periods' in the field
*Membership type*. You will be able to select them the period for the
membership in quantity and interval.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/208/8.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/vertical_association/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 feedback
`here <https://github.com/OCA/vertical_association/issues/new?body=module:%20membership_variable_period%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
Icon
----
Original clipart from:
* http://pixabay.com/es/en-contacto-con-tarjeta-de-cr%C3%A9dito-97574/
* https://openclipart.org/detail/23920/sandglass
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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 http://odoo-community.org.
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import models
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
'name': 'Variable period for memberships',
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'category': 'Association',
'author': 'Antiun Ingeniería S.L., '
'Serv. Tecnol. Avanzados - Pedro M. Baeza, '
'Odoo Community Association (OCA)',
'website': 'http://www.antiun.com',
'depends': [
'membership',
],
'data': [
'views/product_template_views.xml',
'views/res_partner_views.xml',
'data/membership_data.xml',
],
"installable": True,
}
<?xml version="1.0"?>
<openerp>
<data noupdate="1">
<record model="ir.cron" id="cron_membership_check_expiry">
<field name="name">Check membership expiry</field>
<field name="interval_number">1</field>
<field name="priority">10</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'res.partner'"/>
<field name="function" eval="'check_membership_expiry'"/>
<field name="args" eval="'()'"/>
</record>
</data>
</openerp>
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * membership_variable_period
#
# Translators:
# Rudolf Schnapka <rs@techno-flex.de>, 2016
msgid ""
msgstr ""
"Project-Id-Version: vertical-association (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-19 12:02+0000\n"
"PO-Revision-Date: 2016-01-18 20:04+0000\n"
"Last-Translator: Rudolf Schnapka <rs@techno-flex.de>\n"
"Language-Team: German (http://www.transifex.com/oca/OCA-vertical-association-8-0/language/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Fixed dates"
msgstr "Feste Termine"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "Interval"
msgstr "Intervall"
#. module: membership_variable_period
#: field:product.template,membership_interval_qty:0
msgid "Interval quantity"
msgstr "Intervallanzahl"
#. module: membership_variable_period
#: field:product.template,membership_interval_unit:0
msgid "Interval unit"
msgstr "Intervalleinheit"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_account_invoice_line
msgid "Invoice Line"
msgstr "Rechnungsposition"
#. module: membership_variable_period
#: field:account.invoice.line,membership_lines:0
msgid "Membership lines"
msgstr "Mitgliedschafts-Positionen"
#. module: membership_variable_period
#: field:product.template,membership_type:0
msgid "Membership type"
msgstr "Art der Mitgliedschaft"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_res_partner
msgid "Partner"
msgstr "Partner"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_product_template
msgid "Product Template"
msgstr "Produktvorlage"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Variable periods"
msgstr "Variable Perioden"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "days"
msgstr "Tage"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "months"
msgstr "Monate"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "weeks"
msgstr "Wochen"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "years"
msgstr "Jahre"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "{'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.product_template_form_view_membership_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)],"
" 'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)]}"
msgstr ""
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * membership_variable_period
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: vertical-association (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-07 20:26+0000\n"
"PO-Revision-Date: 2015-09-07 20:27+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>\n"
"Language-Team: Spanish (http://www.transifex.com/oca/OCA-vertical-association-8-0/language/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Fixed dates"
msgstr "Fechas fijas"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "Interval"
msgstr "Intervalo"
#. module: membership_variable_period
#: field:product.template,membership_interval_qty:0
msgid "Interval quantity"
msgstr "Cantidad del intervalo"
#. module: membership_variable_period
#: field:product.template,membership_interval_unit:0
msgid "Interval unit"
msgstr "Unidad del intervalo"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_account_invoice_line
msgid "Invoice Line"
msgstr "Línea de factura"
#. module: membership_variable_period
#: field:account.invoice.line,membership_lines:0
msgid "Membership lines"
msgstr "Líneas de afiliación"
#. module: membership_variable_period
#: field:product.template,membership_type:0
msgid "Membership type"
msgstr "Tipo de afiliación"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_res_partner
msgid "Partner"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_product_template
msgid "Product Template"
msgstr "Plantilla de producto"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Variable periods"
msgstr "Periodos variables"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "days"
msgstr "días"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "months"
msgstr "meses"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "weeks"
msgstr "semanas"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "years"
msgstr "años"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "{'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.product_template_form_view_membership_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)],"
" 'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)]}"
msgstr ""
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * membership_variable_period
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-08-21 00:25+0000\n"
"PO-Revision-Date: 2015-08-21 00:25+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Fixed dates"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "Interval"
msgstr ""
#. module: membership_variable_period
#: field:product.template,membership_interval_qty:0
msgid "Interval quantity"
msgstr ""
#. module: membership_variable_period
#: field:product.template,membership_interval_unit:0
msgid "Interval unit"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_account_invoice_line
msgid "Invoice Line"
msgstr ""
#. module: membership_variable_period
#: field:account.invoice.line,membership_lines:0
msgid "Membership lines"
msgstr ""
#. module: membership_variable_period
#: field:product.template,membership_type:0
msgid "Membership type"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_res_partner
msgid "Partner"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_product_template
msgid "Product Template"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Variable periods"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "days"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "months"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "weeks"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "years"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "{'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "{'required': [('membership_type', '=', 'fixed')]}"
msgstr ""
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * membership_variable_period
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: vertical-association (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-10-14 07:14+0000\n"
"PO-Revision-Date: 2015-09-07 20:26+0000\n"
"Last-Translator: <>\n"
"Language-Team: Portuguese (Brazil) (http://www.transifex.com/oca/OCA-vertical-association-8-0/language/pt_BR/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: pt_BR\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Fixed dates"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "Interval"
msgstr ""
#. module: membership_variable_period
#: field:product.template,membership_interval_qty:0
msgid "Interval quantity"
msgstr ""
#. module: membership_variable_period
#: field:product.template,membership_interval_unit:0
msgid "Interval unit"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_account_invoice_line
msgid "Invoice Line"
msgstr "Linha de faturamento"
#. module: membership_variable_period
#: field:account.invoice.line,membership_lines:0
msgid "Membership lines"
msgstr ""
#. module: membership_variable_period
#: field:product.template,membership_type:0
msgid "Membership type"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_res_partner
msgid "Partner"
msgstr ""
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_product_template
msgid "Product Template"
msgstr "Modelo do Produto"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Variable periods"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "days"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "months"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "weeks"
msgstr ""
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "years"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "{'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.product_template_form_view_membership_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)],"
" 'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr ""
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)]}"
msgstr ""
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * membership_variable_period
#
# Translators:
# Matjaž Mozetič <m.mozetic@matmoz.si>, 2015
msgid ""
msgstr ""
"Project-Id-Version: vertical-association (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-09-23 19:13+0000\n"
"PO-Revision-Date: 2015-09-20 19:07+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>\n"
"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-vertical-association-8-0/language/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Fixed dates"
msgstr "Fiksni datumi"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "Interval"
msgstr "Interval"
#. module: membership_variable_period
#: field:product.template,membership_interval_qty:0
msgid "Interval quantity"
msgstr "Količina intervala"
#. module: membership_variable_period
#: field:product.template,membership_interval_unit:0
msgid "Interval unit"
msgstr "Enota intervala"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_account_invoice_line
msgid "Invoice Line"
msgstr "Postavka računa"
#. module: membership_variable_period
#: field:account.invoice.line,membership_lines:0
msgid "Membership lines"
msgstr "Postavke članarin"
#. module: membership_variable_period
#: field:product.template,membership_type:0
msgid "Membership type"
msgstr "Tip članarine"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_res_partner
msgid "Partner"
msgstr "Partner"
#. module: membership_variable_period
#: model:ir.model,name:membership_variable_period.model_product_template
msgid "Product Template"
msgstr "Predloga proizvoda"
#. module: membership_variable_period
#: selection:product.template,membership_type:0
msgid "Variable periods"
msgstr "Variabilna obdobja"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "days"
msgstr "dni"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "months"
msgstr "mesecev"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "weeks"
msgstr "tednov"
#. module: membership_variable_period
#: selection:product.template,membership_interval_unit:0
msgid "years"
msgstr "let"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid "{'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr "{'invisible': [('membership_type', '!=', 'fixed')]}"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.product_template_form_view_membership_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)],"
" 'invisible': [('membership_type', '!=', 'fixed')]}"
msgstr "{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)], 'invisible': [('membership_type', '!=', 'fixed')]}"
#. module: membership_variable_period
#: view:product.template:membership_variable_period.membership_products_form_period
msgid ""
"{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)]}"
msgstr "{'required': [('membership_type', '=', 'fixed'), ('membership', '=', True)]}"
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import product_template
from . import account_invoice
from . import res_partner
# -*- coding: utf-8 -*-
# (c) 2015 Antiun Ingeniería S.L. - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, api, fields
from datetime import timedelta
import math
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
membership_lines = fields.One2many(
comodel_name='membership.membership_line',
inverse_name='account_invoice_line')
def _prepare_membership_line(self, invoice, product, price_unit, line_id):
memb_line_model = self.env['membership.membership_line']
memb_lines = memb_line_model.search(
[('partner', '=', invoice.partner_id.id),
('state', 'not in', ['none', 'canceled'])],
order="date_to desc")
if memb_lines and memb_lines[0].date_to:
date_from = (fields.Date.from_string(memb_lines[0].date_to) +
timedelta(days=1))
else:
date_from = fields.Date.from_string(
invoice.date_invoice or fields.Date.today())
date_to = (product.product_tmpl_id._get_next_date(date_from) -
timedelta(days=1))
return {
'partner': invoice.partner_id.id,
'membership_id': product.id,
'member_price': price_unit,
'date': fields.Date.today(),
'date_from': fields.Date.to_string(date_from),
'date_to': fields.Date.to_string(date_to),
'state': 'waiting',
'account_invoice_line': line_id,
}
@api.multi
def write(self, vals):
"""Create before the lines of membership with variable period."""
memb_line_model = self.env['membership.membership_line']
if any(x in vals for x in ['product_id', 'quantity', 'invoice_id']):
for line in self:
product = (
self.env['product.product'].browse(vals['product_id']) if
vals.get('product_id') else line.product_id)
invoice = (
self.env['account.invoice'].browse(vals['invoice_id']) if
vals.get('invoice_id') else line.invoice_id)
if (invoice.type == 'out_invoice' and
product.membership and
product.membership_type == 'variable'):
quantity = vals.get('quantity', line.quantity)
memb_lines = memb_line_model.search(
[('account_invoice_line', '=', line.id),
('state', 'not in', ['none', 'canceled'])],
order="date desc, id desc")
price_unit = vals.get('price_unit', line.price_unit)
membership_vals = self._prepare_membership_line(
invoice, product, price_unit, line.id)
if len(memb_lines) < quantity:
# Add missing membership lines
missing_number = quantity - len(memb_lines)
for i in range(int(missing_number)):
memb_line_model.create(membership_vals)
elif len(memb_lines) > quantity:
# Remove extra membership lines
extra_number = (
len(memb_lines) - int(math.ceil(quantity)))
memb_lines[:extra_number].unlink()
else:
# Update data of current membership line
memb_lines[0].write(membership_vals)
return super(AccountInvoiceLine, self).write(vals)
@api.model
def create(self, vals):
price_unit = vals.get('price_unit', 0.0)
line = super(AccountInvoiceLine, self).create(vals)
if (line.invoice_id.type == 'out_invoice' and
line.product_id.membership and
line.product_id.membership_type == 'variable'):
for i in range(int(line.quantity)):
membership_vals = self._prepare_membership_line(
line.invoice_id, line.product_id, price_unit, line.id)
# There's already the super line