Browse Source

Changes suggested by @elicoidal and @pedrobaeza. Translate.

pull/26/head
Carlos Incaser 9 years ago
parent
commit
e5d5a813bf
  1. 20
      contract/README.rst
  2. 5
      contract/__openerp__.py
  3. 129
      contract/i18n/account_analytic_analysis_recurring.pot
  4. 286
      contract/i18n/es.po
  5. 86
      contract/models/contract.py
  6. 15
      contract/views/contract.xml

20
contract/README.rst

@ -2,11 +2,12 @@
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
========
Contract
========
=================================
Contracts for recurrent invoicing
=================================
* This module recover contracts management with recurring invoicing functions.
* This module forward-port to v9 the contracts management with recurring
invoicing functions.
Usage
=====
@ -15,21 +16,18 @@ To use this module, you need to:
#. Go to Sales -> Contracts and select or create a new contract.
#. Check *Generate recurring invoices automatically*.
#. Fill fields and add new lines.
#. Fill fields and add new lines. You have the possibility to use markers in
in description field to show init date and end of invoiced period.
#. To view discount field set *Discount on lines* in user access rights.
#. A cron is created with daily interval, but if you are in debug mode can
click on *Create invoices* to force this action.
#. Click *Show invoices* link to show all invoices created by the contract.
#. Press *Invoices* button to show all invoices related with the contract.
.. 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/9.0
For further information, please visit:
* https://www.odoo.com/forum/help-1
Known issues / Roadmap
======================

5
contract/__openerp__.py

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# © 2004-2010 OpenERP SA (<http://openerp.com>)
# © 2016 Incaser Informatica S.L. - Carlos Dauden
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
@ -7,7 +8,9 @@
'version': '9.0.1.0.0',
'category': 'Other',
'license': 'AGPL-3',
'author': "OpenERP SA,Odoo Community Association (OCA)",
'author': "OpenERP SA,"
"Incaser Informatica S.L.,"
"Odoo Community Association (OCA)",
'website': 'http://openerp.com',
'depends': ['base', 'account', 'analytic'],
'data': [

129
contract/i18n/account_analytic_analysis_recurring.pot

@ -1,129 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_analytic_analysis_recurring
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-02-21 11:41+0000\n"
"PO-Revision-Date: 2014-02-21 11:41+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: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,price_subtotal:0
msgid "Sub Total"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_rule_type:0
msgid "Recurrency"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,price_unit:0
msgid "Unit Price"
msgstr ""
#. module: account_analytic_analysis_recurring
#: view:account.analytic.account:0
msgid ". create invoices"
msgstr ""
#. module: account_analytic_analysis_recurring
#: view:account.analytic.account:0
msgid "Account Analytic Lines"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_invoice_line_ids:0
msgid "Invoice Lines"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,uom_id:0
msgid "Unit of Measure"
msgstr ""
#. module: account_analytic_analysis_recurring
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Day(s)"
msgstr ""
#. module: account_analytic_analysis_recurring
#: help:account.analytic.account,recurring_rule_type:0
msgid "Invoice automatically repeat at specified interval"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,product_id:0
msgid "Product"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,name:0
msgid "Description"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_interval:0
msgid "Repeat Every"
msgstr ""
#. module: account_analytic_analysis_recurring
#: view:account.analytic.account:0
msgid "Recurring Invoices"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_invoices:0
msgid "Generate recurring invoices automatically"
msgstr ""
#. module: account_analytic_analysis_recurring
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Year(s)"
msgstr ""
#. module: account_analytic_analysis_recurring
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Week(s)"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,quantity:0
msgid "Quantity"
msgstr ""
#. module: account_analytic_analysis_recurring
#: model:ir.model,name:account_analytic_analysis_recurring.model_account_analytic_invoice_line
msgid "account.analytic.invoice.line"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_next_date:0
msgid "Date of Next Invoice"
msgstr ""
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,analytic_account_id:0
#: model:ir.model,name:account_analytic_analysis_recurring.model_account_analytic_account
msgid "Analytic Account"
msgstr ""
#. module: account_analytic_analysis_recurring
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Month(s)"
msgstr ""
#. module: account_analytic_analysis_recurring
#: help:account.analytic.account,recurring_interval:0
msgid "Repeat every (Days/Week/Month/Year)"
msgstr ""

286
contract/i18n/es.po

@ -1,156 +1,302 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_analytic_analysis_recurring
# * account_analytic_analysis_recurring
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Project-Id-Version: Odoo 9.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-08-18 23:13+0000\n"
"PO-Revision-Date: 2014-08-19 01:14+0100\n"
"Last-Translator: Joaquin Gutierrez <joaquing.pedrosa@gmail.com>\n"
"POT-Creation-Date: 2016-03-25 23:49+0000\n"
"PO-Revision-Date: 2016-03-26 00:49+0100\n"
"Last-Translator: Carlos Incaser <carlos@incaser.es>\n"
"Language-Team: \n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 1.5.4\n"
#. module: account_analytic_analysis_recurring
#: view:account.analytic.account:0
msgid ". create invoices"
msgstr ". crear facturas"
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "<strong>#END#</strong>: End date of the invoiced period"
msgstr "<strong>#END#</strong>: Fecha fin del periodo facturado"
#. module: account_analytic_analysis_recurring
#: view:account.analytic.account:0
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "<strong>#START#</strong>: Start date of the invoiced period"
msgstr "<strong>#START#</strong>: Fecha inicio del periodo facturado"
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "Account Analytic Lines"
msgstr "Ver líneas contables analíticas"
#. module: account_analytic_analysis_recurring
#: code:_description:0
#: field:account.analytic.invoice.line,analytic_account_id:0
#: model:ir.model,name:account_analytic_analysis_recurring.model_account_analytic_account
#, python-format
#. module: contract
#: model:ir.model,name:contract.model_account_analytic_account
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_analytic_account_id
msgid "Analytic Account"
msgstr "Cuenta analítica"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_next_date:0
#. module: contract
#: model:ir.actions.act_window,help:contract.action_account_analytic_overdue_all
msgid "Click to create a new contract."
msgstr "Pinche para crear un contrato nuevo. "
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_invoice_contract_id
msgid "Contract"
msgstr "Contrato"
#. module: contract
#: model:ir.actions.act_window,name:contract.action_account_analytic_overdue_all
#: model:ir.model.fields,field_description:contract.field_account_invoice_analytic_account_ids
#: model:ir.ui.menu,name:contract.menu_action_account_analytic_overdue_all
msgid "Contracts"
msgstr "Contratos"
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "Create invoices"
msgstr "Crear facturas"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_create_uid
msgid "Created by"
msgstr "Creado por"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_create_date
msgid "Created on"
msgstr "Creado en"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_next_date
msgid "Date of Next Invoice"
msgstr "Próximo fecha de factura"
#. module: account_analytic_analysis_recurring
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_date_start
msgid "Date start"
msgstr "Fecha inicio"
#. module: contract
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Day(s)"
msgstr "Día(s)"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,name:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_name
msgid "Description"
msgstr "Descripción"
#. module: account_analytic_analysis_recurring
#: code:addons/account_analytic_analysis_recurring/account_analytic_analysis_recurring.py:165
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_discount
msgid "Discount (%)"
msgstr "Descuento (%)"
#. module: contract
#: code:addons/contract/models/contract.py:56
#, python-format
msgid "Error!"
msgstr "¡Error!"
msgid "Discount should be less or equal to 100"
msgstr "El descuento debería ser menor o igual a 100"
#. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_invoice_line_discount
msgid ""
"Discount that is applied in generated invoices. It should be less or equal "
"to 100"
msgstr ""
"Descuento que es aplicado en las facturas generadas. Debería ser menor o "
"igual a 100"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_invoices:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_display_name
msgid "Display Name"
msgstr "Nombre mostrado"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoices
msgid "Generate recurring invoices automatically"
msgstr "Generar facturas recurrentes automáticamente."
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_invoice_line_ids:0
#. module: contract
#: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search
msgid "Group By..."
msgstr "Agrupar por..."
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_id
msgid "ID"
msgstr "ID (identificación)"
#. module: contract
#: model:ir.model,name:contract.model_account_invoice
msgid "Invoice"
msgstr "Factura"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_invoice_line_ids
msgid "Invoice Lines"
msgstr "Líneas de factura"
#. module: account_analytic_analysis_recurring
#: help:account.analytic.account,recurring_rule_type:0
msgid "Invoice automatically repeat at specified interval"
msgstr "Repetir factura automáticamente en ese intervalo"
#. module: contract
#: model:ir.actions.act_window,name:contract.act_analytic_invoices
#: model:ir.actions.act_window,name:contract.act_recurring_invoices
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "Invoices"
msgstr "Facturas"
#. module: account_analytic_analysis_recurring
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "Invoices related with this contract"
msgstr "Facturas relacionadas con este contrato"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_journal_id
msgid "Journal"
msgstr "Diario"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line___last_update
msgid "Last Modified on"
msgstr "Última modificación en"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_write_uid
msgid "Last Updated by"
msgstr "Última actualización de"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_write_date
msgid "Last Updated on"
msgstr "Última actualización en"
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "Legend (for the markers inside invoice lines description)"
msgstr ""
"Leyenda (para los marcadores dentro de descripción en lineas de factura)"
#. module: contract
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Month(s)"
msgstr "Mes(es)"
#. module: account_analytic_analysis_recurring
#: code:addons/account_analytic_analysis_recurring/account_analytic_analysis_recurring.py:153
#, python-format
msgid "No Customer Defined!"
msgstr "¡No se ha definido un cliente!"
#. module: contract
#: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search
msgid "Next Invoice"
msgstr "Próxima factura"
#. module: account_analytic_analysis_recurring
#: code:addons/account_analytic_analysis_recurring/account_analytic_analysis_recurring.py:166
#. module: contract
#: code:addons/contract/models/contract.py:194
#, python-format
msgid "Please define a sale journal for the company \"%s\"."
msgstr "Defina por favor un diario de ventas para esta compañía \"%s\"."
msgid "Please define a sale journal for the company '%s'."
msgstr "Por favor define un diario de ventas para la compañía '%s'."
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,product_id:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_pricelist_id
msgid "Pricelist"
msgstr "Lista de precios"
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_product_id
msgid "Product"
msgstr "Producto"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,quantity:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_quantity
msgid "Quantity"
msgstr "Cantidad"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_rule_type:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_rule_type
msgid "Recurrency"
msgstr "Recurrencia"
#. module: account_analytic_analysis_recurring
#: view:account.analytic.account:0
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
#: model:ir.ui.view,arch_db:contract.view_account_analytic_account_contract_search
msgid "Recurring Invoices"
msgstr "Facturas recurrentes"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.account,recurring_interval:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_account_recurring_interval
msgid "Repeat Every"
msgstr "Repetir cada"
#. module: account_analytic_analysis_recurring
#: help:account.analytic.account,recurring_interval:0
#. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_interval
msgid "Repeat every (Days/Week/Month/Year)"
msgstr "Repetir cada (días/semana/mes/año)"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,price_subtotal:0
#. module: contract
#: model:ir.model.fields,help:contract.field_account_analytic_account_recurring_rule_type
msgid "Specify Interval for automatic invoice generation."
msgstr "Especifica el intervalo para la generación de facturas automática."
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_price_subtotal
msgid "Sub Total"
msgstr "Subtotal"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,price_unit:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_price_unit
msgid "Unit Price"
msgstr "Precio unidad"
#. module: account_analytic_analysis_recurring
#: field:account.analytic.invoice.line,uom_id:0
#. module: contract
#: model:ir.model.fields,field_description:contract.field_account_analytic_invoice_line_uom_id
msgid "Unit of Measure"
msgstr "Unidad de medida"
#. module: account_analytic_analysis_recurring
#. module: contract
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Week(s)"
msgstr "Semana(s)"
#. module: account_analytic_analysis_recurring
#. module: contract
#: selection:account.analytic.account,recurring_rule_type:0
msgid "Year(s)"
msgstr "Año(s)"
#. module: account_analytic_analysis_recurring
#: code:addons/account_analytic_analysis_recurring/account_analytic_analysis_recurring.py:154
#. module: contract
#: code:addons/contract/models/contract.py:186
#, python-format
msgid "You must first select a Customer for Contract %s!"
msgstr "¡Seleccione un cliente para este contrato %s!"
#. module: account_analytic_analysis_recurring
#: code:_description:0
#: model:ir.model,name:account_analytic_analysis_recurring.model_account_analytic_invoice_line
#, python-format
#. module: contract
#: model:ir.model,name:contract.model_account_analytic_invoice_line
msgid "account.analytic.invoice.line"
msgstr "account.analytic.invoice.line"
#. module: contract
#: model:ir.ui.view,arch_db:contract.account_analytic_account_recurring_form_form
msgid "⇒ Show invoices"
msgstr "⇒ Mostrar facturas"
#, fuzzy
#~ msgid "Recurring Invoice"
#~ msgstr "Recurring Invoice"
#~ msgid ""
#~ "Use contracts to follow tasks, issues, timesheets or invoicing based on\n"
#~ " work done, expenses and/or sales orders. Odoo will "
#~ "automatically manage\n"
#~ " the alerts for the renewal of the contracts to the "
#~ "right salesperson."
#~ msgstr ""
#~ "Use contratos para seguir tareas, incidencias, hojas de trabajo o "
#~ "facturación basada\n"
#~ " en trabajo realizado, gastos y/o pedidos de venta. "
#~ "Odoo gestrionará automáticamente\n"
#~ " las alertas para la renovación de los contratos "
#~ msgid "Error!"
#~ msgstr "¡Error!"
#~ msgid "Invoice automatically repeat at specified interval"
#~ msgstr "Repetir factura automáticamente en ese intervalo"
#~ msgid "No Customer Defined!"
#~ msgstr "¡No se ha definido un cliente!"

86
contract/models/contract.py

@ -33,9 +33,8 @@ class AccountAnalyticInvoiceLine(models.Model):
discount = fields.Float(
string='Discount (%)',
digits=dp.get_precision('Discount'),
copy=True,
help='Discount that is applied in generated invoices.'
' It should be less or equal to 100')
' It should be less or equal to 100')
@api.multi
@api.depends('quantity', 'price_unit', 'discount')
@ -118,13 +117,14 @@ class AccountAnalyticAccount(models.Model):
],
default='monthly',
string='Recurrency',
help="Invoice automatically repeat at specified interval")
help="Specify Interval for automatic invoice generation.")
recurring_interval = fields.Integer(
default=1,
string='Repeat Every',
help="Repeat every (Days/Week/Month/Year)")
recurring_next_date = fields.Date(
default=fields.Date.context_today,
copy=False,
string='Date of Next Invoice')
journal_id = fields.Many2one(
'account.journal',
@ -132,15 +132,6 @@ class AccountAnalyticAccount(models.Model):
default=_default_journal,
domain="[('type', '=', 'sale'),('company_id', '=', company_id)]")
@api.multi
def copy(self, default=None):
default = dict(default or {})
# Reset next invoice date
default.update(
recurring_next_date=self._defaults['recurring_next_date'](self)
)
return super(AccountAnalyticAccount, self).copy(default=default)
@api.onchange('partner_id')
def _onchange_partner_id(self):
self.pricelist_id = self.partner_id.property_product_pricelist.id
@ -159,13 +150,17 @@ class AccountAnalyticAccount(models.Model):
@api.model
def _prepare_invoice_line(self, line, invoice_id):
product = line.product_id
account_id = (product.property_account_income_id.id or
product.categ_id.property_account_income_categ_id.id)
contract = line.analytic_account_id
fpos = contract.partner_id.property_account_position_id
account_id = fpos.map_account(account_id)
taxes = fpos.map_tax(product.taxes_id)
invoice_line = self.env['account.invoice.line'].new({
'invoice_id': invoice_id,
'product_id': line.product_id.id,
'quantity': line.quantity,
'uom_id': line.uom_id.id,
'discount': line.discount,
})
# Get other invoice line values from product onchange
invoice_line._onchange_product_id()
invoice_line_vals = invoice_line._convert_to_write(invoice_line._cache)
name = line.name
if 'old_date' in self.env.context and 'next_date' in self.env.context:
lang_obj = self.env['res.lang']
@ -176,18 +171,13 @@ class AccountAnalyticAccount(models.Model):
name = self._insert_markers(
name, self.env.context['old_date'],
self.env.context['next_date'], date_format)
return {
invoice_line_vals.update({
'name': name,
'account_id': account_id,
'account_analytic_id': contract.id,
'price_unit': line.price_unit,
'quantity': line.quantity,
'uom_id': line.uom_id.id,
'product_id': line.product_id.id,
'invoice_id': invoice_id,
'invoice_line_tax_ids': [(6, 0, taxes.ids)],
'discount': line.discount,
}
})
return invoice_line_vals
@api.model
def _prepare_invoice(self, contract):
@ -195,8 +185,6 @@ class AccountAnalyticAccount(models.Model):
raise ValidationError(
_("You must first select a Customer for Contract %s!") %
contract.name)
partner = contract.partner_id
fpos = partner.property_account_position_id
journal = contract.journal_id or self.env['account.journal'].search(
[('type', '=', 'sale'),
('company_id', '=', contract.company_id.id)],
@ -205,21 +193,30 @@ class AccountAnalyticAccount(models.Model):
raise ValidationError(
_("Please define a sale journal for the company '%s'.") %
(contract.company_id.name or '',))
inv_data = {
currency = (
contract.pricelist_id.currency_id or
contract.partner_id.property_product_pricelist.currency_id or
contract.company_id.currency_id
)
invoice = self.env['account.invoice'].new({
'reference': contract.code,
'account_id': partner.property_account_receivable_id.id,
'type': 'out_invoice',
'partner_id': partner.id,
'currency_id': partner.property_product_pricelist.currency_id.id,
'partner_id': contract.partner_id,
'currency_id': currency.id,
'journal_id': journal.id,
'date_invoice': contract.recurring_next_date,
'origin': contract.name,
'fiscal_position_id': fpos.id,
'payment_term_id': partner.property_payment_term_id.id,
'company_id': contract.company_id.id,
'contract_id': contract.id,
}
invoice = self.env['account.invoice'].create(inv_data)
})
# Get other invoice values from partner onchange
invoice._onchange_partner_id()
return invoice._convert_to_write(invoice._cache)
@api.model
def _create_invoice(self, contract):
invoice_vals = self._prepare_invoice(contract)
invoice = self.env['account.invoice'].create(invoice_vals)
for line in contract.recurring_invoice_line_ids:
invoice_line_vals = self._prepare_invoice_line(line, invoice.id)
self.env['account.invoice.line'].create(invoice_line_vals)
@ -234,16 +231,15 @@ class AccountAnalyticAccount(models.Model):
('account_type', '=', 'normal'),
('recurring_invoices', '=', True)])
for contract in contracts:
next_date = fields.Date.from_string(
old_date = fields.Date.from_string(
contract.recurring_next_date or fields.Date.today())
interval = contract.recurring_interval
old_date = next_date
if contract.recurring_rule_type == 'daily':
new_date = next_date + relativedelta(days=interval)
new_date = old_date + relativedelta(days=interval)
elif contract.recurring_rule_type == 'weekly':
new_date = next_date + relativedelta(weeks=interval)
new_date = old_date + relativedelta(weeks=interval)
else:
new_date = next_date + relativedelta(months=interval)
new_date = old_date + relativedelta(months=interval)
ctx = self.env.context.copy()
ctx.update({
'old_date': old_date,
@ -252,8 +248,8 @@ class AccountAnalyticAccount(models.Model):
'force_company': contract.company_id.id,
})
# Re-read contract with correct company
contract = self.with_context(ctx).browse(contract.id)
self.with_context(ctx)._prepare_invoice(contract)
contract = contract.with_context(ctx)
self.with_context(ctx)._create_invoice(contract)
contract.write({
'recurring_next_date': new_date.strftime('%Y-%m-%d')
})

15
contract/views/contract.xml

@ -46,7 +46,7 @@
groups="base.group_no_one"/>
<button name="%(contract.act_recurring_invoices)d" type="action"
attrs="{'invisible': [('recurring_invoices','!=',True)]}"
string="⇒ show invoices" class="oe_link"/>
string="⇒ Show invoices" class="oe_link"/>
</div>
<group attrs="{'invisible': [('recurring_invoices','!=',True)]}">
<field name="journal_id"/>
@ -73,6 +73,11 @@
</tree>
</field>
</div>
<group string="Legend (for the markers inside invoice lines description)"
name="group_legend" attrs="{'invisible': [('recurring_invoices','!=',True)]}">
<p colspan="2"> <strong>#START#</strong>: Start date of the invoiced period</p>
<p colspan="2"> <strong>#END#</strong>: End date of the invoiced period</p>
</group>
</notebook>
</field>
</record>
@ -98,7 +103,7 @@
<field name="name" position="after">
<field name="journal_id"/>
<field name="pricelist_id"/>
<filter name="recurring_invoice" string="Recurring Invoice" domain="[('recurring_invoices','=',True)]"/>
<filter name="recurring_invoices" string="Recurring Invoices" domain="[('recurring_invoices','=',True)]"/>
<group expand="0" string="Group By...">
<filter string="Next Invoice" domain="[]" context="{'group_by':'recurring_next_date'}"/>
</group>
@ -112,15 +117,11 @@
<field name="res_model">account.analytic.account</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_active':1, 'search_default_recurring_invoice':1}</field>
<field name="context">{'search_default_active':1, 'search_default_recurring_invoices':1}</field>
<field name="search_view_id" ref="analytic.view_account_analytic_account_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new contract.
</p><p>
Use contracts to follow tasks, issues, timesheets or invoicing based on
work done, expenses and/or sales orders. Odoo will automatically manage
the alerts for the renewal of the contracts to the right salesperson.
</p>
</field>
</record>

Loading…
Cancel
Save