# -*- coding: utf-8 -*-
##############################################################################
-#
+#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import account_analytic_analysis
import res_config
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
+import product_template
+import sale_order
'account_analytic_analysis_cron.xml',
'res_config_view.xml',
'views/account_analytic_analysis.xml',
+ 'product_template_view.xml',
],
'demo': ['analytic_account_demo.xml'],
'test': ['test/account_analytic_analysis.yml'],
--- /dev/null
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields
+
+
+class product_template(models.Model):
+ """ Add recurrent_invoice field to product template if it is true,
+ it will add to related contract.
+ """
+ _inherit = "product.template"
+
+ recurring_invoice = fields.Boolean(
+ string='Recurrent Invoice Product', default=False,
+ help="If selected, this product will be added to the "
+ "related contract (which must be associated with the SO). \n"
+ "It will be used as product for invoice lines and generate "
+ "the recurring invoices automatically")
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+
+ <record id="view_product_template_recurrent_form_inherit" model="ir.ui.view">
+ <field name="name">product_template_form_view.inherit</field>
+ <field name="model">product.template</field>
+ <field name="inherit_id" ref="product.product_template_form_view"/>
+ <field name="arch" type="xml">
+ <xpath expr="//group[@name='sale_condition']" position="after">
+ <group name="contract" string="Contract" colspan="3">
+ <field name="recurring_invoice" class="oe_inline"/>
+ </group>
+ </xpath>
+ </field>
+ </record>
+
+ </data>
+</openerp>
--- /dev/null
+# -*- coding: utf-8 -*-
+
+from openerp import models, api
+
+
+class sale_order_line(models.Model):
+ _inherit = "sale.order.line"
+
+ @api.one
+ def button_confirm(self):
+ if self.product_id.recurring_invoice and self.order_id.project_id:
+ invoice_line_ids = [((0, 0, {
+ 'product_id': self.product_id.id,
+ 'analytic_account_id': self.order_id.project_id.id,
+ 'name': self.name,
+ 'quantity': self.product_uom_qty,
+ 'uom_id': self.product_uom.id,
+ 'price_unit': self.price_unit,
+ 'price_subtotal': self.price_subtotal
+ }))]
+ analytic_values = {'recurring_invoices': True, 'recurring_invoice_line_ids': invoice_line_ids}
+ if not self.order_id.project_id.partner_id:
+ analytic_values['partner_id'] = self.order_id.partner_id.id
+ self.order_id.project_id.write(analytic_values)
+ return super(sale_order_line, self).button_confirm()