adrielso пре 7 година
комит
6fdb057e5d

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 22 - 0
README.md

@@ -0,0 +1,22 @@
+# Eiru Invoice Status Change
+
+Este modulo fue construido para facilitar el cambio de estado de las facturas  tanto de compras como de ventas.
+
+### Instalación del módulo
+
+1. Clone el proyecto en la raíz de su carpeta de custom addons.
+4. Actualice su lista de módulos y luego instale.
+
+### Como Funciona
+
+1. Solo tendrás que acceder a una factura, y el modulo hará todo le calculo necesario.
+
+    ```
+        Si (residual > 0 && state =='paid'){
+            state= 'open'
+        }
+
+        Si (residual <= 0 && state =='open'){
+            state= 'paid'
+        }
+    ```

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import  model

+ 13 - 0
__openerp__.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+{
+    'name': 'Eiru Invoice Status Change',
+    'version': '1.0',
+    'author': 'Adrielso Kunert',
+    'category': 'Account',
+    'depends': ['account', 'base'],
+        'data': [
+                    'views/templates.xml',
+                ],
+    'installable': True,
+    'auto_install': False,
+ }

+ 2 - 0
model/__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import  eiru_invoice_status_change

+ 27 - 0
model/eiru_invoice_status_change.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+from openerp import api, fields, models
+
+class InvoiceChangeStatus(models.Model):
+    _inherit = 'account.invoice'
+
+    @api.model
+    def update_invoice_state(self, ids):
+        updateInvoice=None
+        invoiceState = None
+
+        accountInvoice = self.env['account.invoice'].browse(ids)
+
+        if (not accountInvoice):
+            return
+
+        if (accountInvoice.residual > 0 and accountInvoice.state == 'paid'):
+            invoiceState = 'open'
+
+        if (accountInvoice.residual <= 0 and accountInvoice.state == 'open'):
+            invoiceState = 'paid'
+
+        if (invoiceState):
+            updateInvoice = accountInvoice.write({'state': invoiceState})
+
+        return True if (updateInvoice) else False

BIN
static/description/icon.png


+ 90 - 0
static/src/js/eiru_invoice_status_change.js

@@ -0,0 +1,90 @@
+openerp.eiru_invoice_status_change = function(instance, local) {
+
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.PayslipGeneratorWidget = instance.Widget.extend({
+        id: undefined,
+
+        init: function(parent) {
+            this._super(parent);
+        },
+        /**
+         * [checkState]
+         */
+        checkState: function(id) {
+            var self = this;
+            self.id = id;
+        
+            if (id)
+                self.fectchInitial();
+        },
+        /**
+         * [fectchInitial]
+         */
+        fectchInitial: function() {
+            var self = this;
+            self.fectchInvoice(self.id).then(function(accountInvoice) {
+                return accountInvoice;
+            }).then(function(accountInvoice) {
+                if (!accountInvoice.length)
+                    return false
+                return self.updateInvoiceState(accountInvoice.shift());
+            }).then(function(update){
+                if (update)
+                    return self.reloadPage()
+            })
+        },
+        /**
+         * [fectchInvoice]
+         */
+        fectchInvoice: function(id) {
+            var invoice = new instance.web.Model('account.invoice');
+            var fields = ['id','name','residual', 'state'];
+            var domain = [['id', '=', id],['state', 'in', ['open', 'paid']]];
+            return invoice.query(fields).filter(domain).all();
+        },
+        /**
+         * [updateInvoiceState]
+         */
+        updateInvoiceState: function(invoice) {
+            if (invoice.residual <= 0 && invoice.state === 'paid')
+                return
+            if (invoice.residual > 0 && invoice.state === 'open')
+                return
+
+            var invoiceUpdate = new instance.web.Model('account.invoice');
+            return invoiceUpdate.call('update_invoice_state',[invoice.id], {
+                context: new instance.web.CompoundContext()
+            })
+        },
+        /**
+         * [reloadPage]
+         */
+        reloadPage: function() {
+             local.parentInstance.reload();
+        },
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'account.invoice')
+                    return;
+
+                local.parentInstance = this;
+
+                if (local.widgetInstance) {
+                    local.widgetInstance.checkState(record.id);
+                    return
+                }
+
+                local.widgetInstance = new local.PayslipGeneratorWidget(this);
+                local.widgetInstance.checkState(record.id);
+
+            }
+        });
+    }
+}

+ 9 - 0
views/templates.xml

@@ -0,0 +1,9 @@
+<openerp>
+    <data>
+        <template id="eiru_payslip_utility.eiru_assets" name="aeiru_payslip_payments_eiru_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/eiru_invoice_status_change/static/src/js/eiru_invoice_status_change.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>