[IMP] account_analytic_analysis : Add recurring field to product and add product...
authorJamin Shah <jas@openerp.com>
Tue, 9 Sep 2014 12:26:33 +0000 (17:56 +0530)
committerThibault Delavallée <tde@openerp.com>
Wed, 29 Oct 2014 15:38:57 +0000 (16:38 +0100)
addons/account_analytic_analysis/__init__.py
addons/account_analytic_analysis/__openerp__.py
addons/account_analytic_analysis/product_template.py [new file with mode: 0644]
addons/account_analytic_analysis/product_template_view.xml [new file with mode: 0644]
addons/account_analytic_analysis/sale_order.py [new file with mode: 0644]

index be5a6e4..a98abe8 100644 (file)
@@ -1,6 +1,6 @@
 # -*- 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
index 2049875..7c9a64f 100644 (file)
@@ -41,6 +41,7 @@ Adds menu to show relevant information to each manager.You can also view the rep
         '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'],
diff --git a/addons/account_analytic_analysis/product_template.py b/addons/account_analytic_analysis/product_template.py
new file mode 100644 (file)
index 0000000..07b3ce9
--- /dev/null
@@ -0,0 +1,17 @@
+# -*- 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")
diff --git a/addons/account_analytic_analysis/product_template_view.xml b/addons/account_analytic_analysis/product_template_view.xml
new file mode 100644 (file)
index 0000000..3a24fb3
--- /dev/null
@@ -0,0 +1,19 @@
+<?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>
diff --git a/addons/account_analytic_analysis/sale_order.py b/addons/account_analytic_analysis/sale_order.py
new file mode 100644 (file)
index 0000000..e52e185
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- 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()