Browse Source

Para giganet vencimiento en contrato

sebas 4 years ago
commit
9e3f268024

+ 73 - 0
README.rst

@@ -0,0 +1,73 @@
+.. 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
+
+=========================
+Contracts Recurring Total
+=========================
+
+Add recurring total amount for contracts on tree and form view
+
+Installation
+============
+
+To install this module, you need to:
+
+#. Just Install this module
+
+Configuration
+=============
+
+To configure this module, you need to:
+
+#. No configuration needed
+
+Usage
+=====
+
+To use this module, you need to:
+
+#. Go to contracts and check for new fiel "Recurring Total"
+
+.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
+   :alt: Try me on Runbot
+   :target: https://runbot.adhoc.com.ar/
+
+.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
+.. branch is "8.0" for example
+
+Known issues / Roadmap
+======================
+
+* ...
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues
+<https://github.com/ingadhoc/{project_repo}/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.
+
+Credits
+=======
+
+Images
+------
+
+* ADHOC SA: `Icon <http://fotos.subefotos.com/83fed853c1e15a8023b86b2b22d6145bo.png>`_.
+
+Contributors
+------------
+
+
+Maintainer
+----------
+
+.. image:: http://fotos.subefotos.com/83fed853c1e15a8023b86b2b22d6145bo.png
+   :alt: Odoo Community Association
+   :target: https://www.adhoc.com.ar
+
+This module is maintained by the ADHOC SA.
+
+To contribute to this module, please visit https://www.adhoc.com.ar.

+ 6 - 0
__init__.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+# For copyright and license notices, see __openerp__.py file in module root
+# directory
+##############################################################################
+from . import account_analytic_account

BIN
__init__.pyc


+ 46 - 0
__openerp__.py

@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2016  ADHOC SA  (http://www.adhoc.com.ar)
+#    All Rights Reserved.
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    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/>.
+#
+##############################################################################
+{
+    'name': 'Contracts Recurring Total',
+    'version': '8.0.1.0.0',
+    'category': 'Sales Management',
+    'sequence': 14,
+    'summary': '',
+    'author': 'ADHOC SA',
+    'website': 'www.adhoc.com.ar',
+    'license': 'AGPL-3',
+    'images': [
+    ],
+    'depends': [
+        'account_analytic_analysis',
+        'account',
+    ],
+    'data': [
+        'account_analytic_account_view.xml'
+    ],
+    'demo': [
+    ],
+    'test': [
+    ],
+    'installable': True,
+    'auto_install': False,
+    'application': False,
+}

+ 66 - 0
account_analytic_account.py

@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+# For copyright and license notices, see __openerp__.py file in module root
+# directory
+##############################################################################
+
+from dateutil.relativedelta import relativedelta
+from datetime import datetime
+import logging
+import time
+
+from openerp import models, fields, api
+from openerp.addons.decimal_precision import decimal_precision as dp
+
+
+class account_analytic_account(models.Model):
+    _inherit = "account.analytic.account"
+
+    recurring_date_due = fields.Date("Fecha de vencimiento")
+    recurring_day = fields.Char("Día Vencimiento")
+    recurring_total_amount = fields.Float(
+        'Monto',
+        compute='_compute_recurring_total_amount',
+        # we dont make storable so it is compatible with contract
+        # discount
+        # store=True,
+        digits=dp.get_precision('Account'),
+    )
+    _defaults = {
+        'recurring_date_due': lambda *a: time.strftime('%Y-%m-%d')
+    }
+
+    @api.one
+    @api.depends(
+        'recurring_invoice_line_ids.quantity',
+        'recurring_invoice_line_ids.price_unit',
+    )
+    def _compute_recurring_total_amount(self):
+        self.recurring_total_amount = sum(
+            self.recurring_invoice_line_ids.mapped('price_subtotal'))
+
+    @api.multi
+    def recurring_create_invoice(self):
+            current_date = time.strftime('%Y-%m-%d')
+            if(self.recurring_date_due, '<=', current_date):
+                value = super(account_analytic_account, self).recurring_create_invoice()
+                date_due=self.recurring_date_due
+                for each in value:
+                    invoice = self.env['account.invoice'].search([('id','=',each)])
+                    invoice.write({'date_due': date_due})
+                    self.recurring_date_due = (datetime.strptime(self.recurring_date_due,'%Y-%m-%d') + relativedelta(months=1)).strftime('%Y-%m-%d')
+                return value
+            else:
+                raise Warning(_("Ya no puede generar cuotas para este contrato."))
+
+
+    @api.model
+    def recurring_create_invoice_giganet(self):
+        value = super(account_analytic_account, self)._cron_recurring_create_invoice()
+        for each in value:
+            invoice = self.env['account.invoice'].search([('id','=',each)])
+            contract = self.env['account.analytic.account'].search([('code','=',invoice.origin)])
+            contract.recurring_date_due = (datetime.strptime(self.recurring_date_due,'%Y-%m-%d') + relativedelta(months=1)).strftime('%Y-%m-%d')
+            self.env.cr.execute('update account_analytic_account set recurring_date_due = %s where id = %s', (contract.recurring_date_due, contract.id))
+            self.env.cr.execute('update account_invoice set date_due = %s where  id = %s', (date_due, invoice.id))
+        return value

BIN
account_analytic_account.pyc


+ 32 - 0
account_analytic_account_view.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<openerp>
+<data>
+
+<record id="view_account_analytic_account_form" model="ir.ui.view">
+    <field name="name">account.analytic.account.form</field>
+    <field name="model">account.analytic.account</field>
+    <field name="inherit_id" ref="account_analytic_analysis.account_analytic_account_form_form"/>
+    <field name="arch" type="xml">
+       <field name="recurring_next_date" position="before">
+         <field name="recurring_date_due"/>
+       </field>
+        <field name="price_subtotal" position="attributes">
+            <attribute name="sum">Total</attribute>
+        </field>
+    </field>
+</record>
+
+<record id="view_account_analytic_account_tree_c2c_3" model="ir.ui.view">
+    <field name="name">account.analytic.account.list</field>
+    <field name="model">account.analytic.account</field>
+    <field name="inherit_id" ref="account_analytic_analysis.view_account_analytic_account_tree_c2c_3"/>
+    <field name="arch" type="xml">
+        <field name="company_id" position="after">
+            <field name="recurring_date_due"/>
+            <field name="recurring_total_amount" sum="Total"/>
+        </field>
+    </field>
+</record>
+
+</data>
+</openerp>

+ 17 - 0
account_analytic_analysis_cron.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding='UTF-8'?>
+<openerp>
+    <data>
+
+
+        <record model="ir.cron" id="account_analytic_cron_for_invoice_customer">
+           <field name="name">Generate Recurring Invoices Suppliers from Contracts </field>
+           <field name="interval_number">1</field>
+           <field name="interval_type">days</field>
+           <field name="numbercall">-1</field>
+           <field name="model" eval="'account.analytic.account'"/>
+           <field name="function" eval="'__cron_recurring_create_invoice'"/>
+           <field name="args" eval="'()'"/>
+        </record>
+
+    </data>
+</openerp>