Przeglądaj źródła

actualizar y nro de cuota y total de cuota en contrato

SEBAS 21 godzin temu
commit
6484622b19

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- encoding: utf-8 -*-
+import models

BIN
__init__.pyc


+ 23 - 0
__openerp__.py

@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+
+{
+    'name': 'Cuota en Contrato',
+    'version': '8.0.0.1.0',
+    'category': '',
+    'summary': '',
+    'author': 'Sebastian Penayo/Eiru Software',
+    'license': 'AGPL-3',
+    'depends': [
+        'base',
+        'product',
+        'sale',
+        'account_analytic_analysis',
+        ],
+    'data': [
+        'security/readonly_fields.xml',
+        'views/account_analytic_account.xml',
+        'views/account_invoice.xml',
+    ],
+
+    'installable': True,
+}

+ 3 - 0
models/__init__.py

@@ -0,0 +1,3 @@
+# -*- encoding: utf-8 -*-
+import analytic_account
+import account_invoice

BIN
models/__init__.pyc


+ 10 - 0
models/account_invoice.py

@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, api,_
+from openerp.exceptions import Warning
+
+class AnalyticAccount(models.Model):
+    _inherit = 'account.invoice'
+
+    # cuotas
+    cuotas = fields.Char(string="Cuotas")
+    cuota_total = fields.Integer(string="Total de cuotas")

BIN
models/account_invoice.pyc


+ 180 - 0
models/analytic_account.py

@@ -0,0 +1,180 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, api, _
+from openerp.exceptions import Warning
+
+
+class AnalyticAccount(models.Model):
+    _inherit = 'account.analytic.account'
+
+    # ==========================================================
+    # CUOTAS
+    # ==========================================================
+
+    cuota_total = fields.Integer(
+        string='Total de cuotas',
+        default=0
+    )
+
+    nro_cuotas = fields.Integer(
+        string='Cuotas generadas',
+        readonly=True,
+        default=0
+    )
+
+    cuotas_restantes = fields.Integer(
+        string='Cuotas restantes',
+        compute='_compute_estado_cuotas',
+        store=True
+    )
+
+    porcentaje_cuotas = fields.Float(
+        string='% Cumplimiento',
+        compute='_compute_estado_cuotas',
+        store=True
+    )
+
+    estado_cuotas = fields.Selection([
+        ('curso', 'En Curso'),
+        ('finalizado', 'Finalizado')
+    ], string='Estado',
+       compute='_compute_estado_cuotas',
+       store=True)
+
+    # ==========================================================
+    # ESTADO DEL CONTRATO
+    # ==========================================================
+
+    @api.depends('cuota_total', 'nro_cuotas')
+    def _compute_estado_cuotas(self):
+
+        for rec in self:
+
+            restantes = rec.cuota_total - rec.nro_cuotas
+
+            if restantes < 0:
+                restantes = 0
+
+            rec.cuotas_restantes = restantes
+
+            if rec.cuota_total:
+
+                rec.porcentaje_cuotas = (
+                    float(rec.nro_cuotas) * 100.0
+                ) / rec.cuota_total
+
+            else:
+                rec.porcentaje_cuotas = 0
+
+            if rec.cuota_total and rec.nro_cuotas >= rec.cuota_total:
+                rec.estado_cuotas = 'finalizado'
+            else:
+                rec.estado_cuotas = 'curso'
+
+    # ==========================================================
+    # ACTUALIZA FACTURA
+    # ==========================================================
+
+    def _actualizar_facturas(self, invoice_ids):
+
+        Invoice = self.env['account.invoice']
+
+        for contract in self:
+
+            nueva_cuota = contract.nro_cuotas + 1
+
+            if contract.cuota_total:
+
+                if nueva_cuota > contract.cuota_total:
+                    raise Warning(_("Ya no puede generar más cuotas para este contrato."))
+
+            cuota = "%s/%s" % (
+                nueva_cuota,
+                contract.cuota_total
+            )
+
+            invoices = Invoice.browse(invoice_ids)
+
+            for invoice in invoices:
+
+                if invoice.origin != contract.code:
+                    continue
+
+                invoice.write({
+                    'cuotas': cuota,
+                    'cuota_total': contract.cuota_total,
+                })
+
+                for line in invoice.invoice_line:
+
+                    descripcion = "%s %s" % (
+                        line.product_id.name,
+                        cuota
+                    )
+
+                    line.write({
+                        'name': descripcion
+                    })
+
+            contract.write({
+                'nro_cuotas': nueva_cuota
+            })
+
+    # ==========================================================
+    # FACTURA MANUAL
+    # ==========================================================
+
+    @api.multi
+    def recurring_create_invoice(self):
+
+        invoice_ids = super(
+            AnalyticAccount,
+            self
+        ).recurring_create_invoice()
+
+        if invoice_ids:
+            self._actualizar_facturas(invoice_ids)
+
+        return invoice_ids
+
+    # ==========================================================
+    # FACTURA AUTOMATICA (CRON)
+    # ==========================================================
+
+    @api.model
+    def recurring_create_invoice_inmobiliaria(self):
+
+        invoice_ids = super(
+            AnalyticAccount,
+            self
+        )._cron_recurring_create_invoice()
+
+        if invoice_ids:
+
+            contratos = self.search([])
+
+            contratos._actualizar_facturas(invoice_ids)
+
+        return invoice_ids
+
+    # ==========================================================
+    # DUPLICAR CONTRATO
+    # ==========================================================
+
+    @api.multi
+    def copy(self, default=None):
+
+        default = dict(default or {})
+
+        default.update({
+
+            'nro_cuotas': 0,
+
+            'estado_cuotas': 'curso'
+
+        })
+
+        return super(
+            AnalyticAccount,
+            self
+        ).copy(default)

BIN
models/analytic_account.pyc


+ 8 - 0
security/readonly_fields.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+<data noupdate="0">
+    <record id="readonly_fields_inmobiliaria" model="res.groups">
+        <field name="name">Permitir editar cuotas</field>
+    </record>
+</data>
+</openerp>

BIN
static/description/icon.png


+ 68 - 0
views/account_analytic_account.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <!-- ==========================================================
+             FORMULARIO CONTRATO
+        =========================================================== -->
+
+        <record id="contrato_form_view" model="ir.ui.view">
+            <field name="name">account.analytic.account.cuotas.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">
+
+                    <separator string="Control de Cuotas"/>
+
+                    <group>
+
+                        <field name="cuota_total"/>
+
+                        <field name="nro_cuotas" readonly="1"/>
+
+                        <field name="cuotas_restantes" readonly="1"/>
+
+                        <field name="estado_cuotas" readonly="1"/>
+
+                        <field name="porcentaje_cuotas"
+                               widget="progressbar"
+                               readonly="1"/>
+
+                    </group>
+
+                </field>
+
+            </field>
+        </record>
+
+
+        <!-- ==========================================================
+             CODIGO SOLO LECTURA
+        =========================================================== -->
+
+        <record id="contrato_form_view_codigo"
+                model="ir.ui.view">
+
+            <field name="name">account.analytic.account.code.readonly</field>
+
+            <field name="model">account.analytic.account</field>
+
+            <field name="inherit_id"
+                   ref="analytic.view_account_analytic_account_form"/>
+
+            <field name="arch" type="xml">
+
+                <field name="code" position="replace">
+
+                    <field name="code" readonly="1"/>
+
+                </field>
+
+            </field>
+
+        </record>
+
+    </data>
+</openerp>

+ 18 - 0
views/account_invoice.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record model="ir.ui.view" id="invoice_form">
+       <field name="name">invoice_form</field>
+       <field name="model">account.invoice</field>
+       <field name="inherit_id" ref="account.invoice_form"/>
+       <field name="arch" type="xml">
+          <field name="number" position="after">
+            <field name="cuotas" readonly="1"/>
+          </field>
+          <field name="origin" position="replace">
+            <field name="origin" readonly="1"/>
+          </field>
+      </field>
+    </record>
+</data>
+</openerp>