ソースを参照

Limite de credito en cliente

Your Name 4 年 前
コミット
20acda7bc4

+ 6 - 0
__init__.py

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

BIN
__init__.pyc


+ 44 - 0
__openerp__.py

@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Copyright (C) 2015  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': 'Validaciones ',
+    'version': '8.0.1.1.0',
+    'summary': '',
+    'description': """
+        Valida:
+        -límite de crédito
+        -stock
+    """,
+    'author': 'Eiru',
+    'license': 'AGPL-3',
+    'depends': [
+        'sale',
+        'purchase',
+        'account',
+        'eiru_payments_invoices'],
+    'data': [
+        'views/template.xml',
+        'views/partner_view.xml',
+
+        ],
+    'installable': True,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

+ 3 - 0
models/__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import account_invoice
+import sale

BIN
models/__init__.pyc


+ 60 - 0
models/account_invoice.py

@@ -0,0 +1,60 @@
+#-*- coding:utf-8 -*-
+from openerp import models, api, _
+from openerp.exceptions import Warning
+from datetime import datetime, date
+
+
+class account_invoice(models.Model):
+    _inherit = "account.invoice"
+
+    def invoice_validate(self):
+        self.check_limit()
+       # self.check_morosidad()
+        return super(account_invoice, self).invoice_validate()
+
+    @api.one
+    def check_limit(self):
+
+        if self.contado == True:
+            return True
+
+        available_credit = self.partner_id.credit_limit - self.partner_id.credit
+
+        if self.amount_total > available_credit:
+            msg = 'No se puede confirmar la factura ya que el cliente no tiene crédito suficiente.\
+                    Pruebe marcar la opción "Contado"'
+            raise Warning(_(msg))
+            return False
+        return True
+
+    # @api.multi
+    # def check_morosidad(self):
+    #    now = datetime.now()
+    #    hoy = datetime.strptime(now.strftime("%Y-%m-%d"),"%Y-%m-%d")
+    #    domain = [('id', '=', self.partner_id.id)]
+    #    partner = self.env['res.partner'].search(domain)
+    #    invoices = self.env['account.invoice'].search([('partner_id', '=',self.partner_id.id),('state', '=','open'),('type', '=', 'out_invoice'),('journal_id.type','=','sale')])
+    #    for item in invoices:
+    #        moveLine = self.env['account.move.line'].search([('move_id','=', item.move_id.id),('debit','>',0)])
+    #        if moveLine.date_maturity < now.strftime("%Y-%m-%d"):
+    #            vencimiento = datetime.strptime(moveLine.date_maturity,"%Y-%m-%d")
+    #            if (hoy-vencimiento).days > partner.morosidad:
+    #                raise Warning(_("El cliente %s tiene cuotas vencidas con más de %s días de atraso") % (partner.name, partner.morosidad))
+    #                return False
+    #    return True
+
+    # @api.model
+    # def save_payments_invoice(self,values):
+    #
+    #     bank_payments_type_id = values['bankPayments']['bank_payments_type_id']
+    #     partner = self.env['res.partner'].browse(values['partnerId'])
+    #
+    #     if bank_payments_type_id is not None:
+    #         payment_type = self.env['res.bank.payments.type'].browse(bank_payments_type_id)
+    #         if payment_type.code == 'CH' and values['amountPayments'] > partner.check_limit:
+    #             return {
+    #                 'process': False,
+    #                 'removeModal': False,
+    #                 'message' : "El monto a pagar excede el límite de crédito concedido en cheques"
+    #             }
+    #     return self.env['account.invoice'].save_payments_invoice(values)

BIN
models/account_invoice.pyc


+ 45 - 0
models/sale.py

@@ -0,0 +1,45 @@
+#-*- coding:utf-8 -*-
+from openerp import models, api, _
+from openerp.exceptions import Warning
+from datetime import datetime, date
+
+
+class sale_order(models.Model):
+    _inherit = "sale.order"
+
+    @api.one
+    def action_wait(self):
+        self.check_limit()
+        # self.check_morosidad()
+        return super(sale_order, self).action_wait()
+
+    @api.one
+    def check_limit(self):
+
+        if self.contado == True:
+            return True
+
+        available_credit = self.partner_id.credit_limit - self.partner_id.credit
+
+        if self.amount_total > available_credit:
+            msg = 'No se puede confirmar el Pedido ya que el cliente no tiene crédito suficiente.\
+                    Pruebe marcar la opción "Contado"'
+            raise Warning(_(msg))
+            return False
+        return True
+
+    #@api.one
+    #def check_morosidad(self):
+    #    now = datetime.now()
+    #    hoy = datetime.strptime(now.strftime("%Y-%m-%d"),"%Y-%m-%d")
+    #    domain = [('id', '=', self.partner_id.id)]
+    #    partner = self.env['res.partner'].search(domain)
+    #    invoices = self.env['account.invoice'].search([('partner_id', '=',self.partner_id.id),('state', '=','open'),('type', '=', 'out_invoice'),('journal_id.type','=','sale')])
+    #    for item in invoices:
+    #        moveLine = self.env['account.move.line'].search([('move_id','=', item.move_id.id),('debit','>',0)])
+    #        if moveLine.date_maturity < now.strftime("%Y-%m-%d"):
+    #            vencimiento = datetime.strptime(moveLine.date_maturity,"%Y-%m-%d")
+    #            if partner.morosidad > 0 and (hoy-vencimiento).days > partner.morosidad:
+    #                raise Warning(_("El cliente %s tiene cuotas vencidas con más de %s días de atraso") % (partner.name, partner.morosidad))
+    #                return False
+    #    return True

BIN
models/sale.pyc


BIN
static/description/icon.png


+ 32 - 0
static/src/js/warning.js

@@ -0,0 +1,32 @@
+openerp.partner_credit_limit = function(instance){
+  var QWeb = instance.web.qweb;
+  _t = instance.web._t;
+
+  instance.web.CrashManager.include({
+
+    show_warning: function(error) {
+      if (!this.active) {
+        return;
+      }
+      if (error.data.exception_type === "except_osv") {
+        error = _.extend({}, error, {
+          data: _.extend({}, error.data, {
+            message: error.data.arguments[0] + "\n\n" + error.data.arguments[1]
+          })
+        });
+      }
+      new instance.web.Dialog(this, {
+        size: 'medium',
+        title: "Aviso del sistema ",
+        buttons: [{
+          text: _t("Ok"),
+          click: function() {
+            this.parents('.modal').modal('hide');
+          }
+        }],
+      }, $('<div>' + QWeb.render('CrashManager.warning', {
+        error: error
+      }) + '</div>')).open();
+    },
+  });
+}

+ 30 - 0
views/partner_view.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <!-- make readonly for everyone -->
+        <record id="view_credit_readonly_partner_form" model="ir.ui.view">
+            <field name="name">res.partner.partner_credit_limit.form</field>
+            <field name="model">res.partner</field>
+            <field name="inherit_id" ref="account.view_partner_property_form"/>
+            <field name="groups_id" eval="[(6, 0, [ref('base.group_sale_salesman')])]"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='credit_limit']" position="attributes">
+                    <attribute name="readonly">1</attribute>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="view_credit_readonly_partner_form2" model="ir.ui.view">
+            <field name="name">res.partner.partner_credit_limit.form</field>
+            <field name="model">res.partner</field>
+            <field name="inherit_id" ref="partner_credito_limite.view_credit_readonly_partner_form"/>
+            <field name="groups_id" eval="[(6, 0, [ref('base.group_sale_manager')])]"/>
+            <field name="arch" type="xml">
+                <xpath expr="//field[@name='credit_limit']" position="attributes">
+                    <attribute name="readonly">0</attribute>
+                </xpath>
+            </field>
+        </record>
+
+    </data>
+</openerp>

+ 10 - 0
views/template.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <template id="partner_credit_limit_assets_backend" inherit_id="web.assets_backend">
+      <xpath expr="." position="inside">
+        <script type="text/javascript" src="/partner_credito_limite/static/src/js/warning.js"/>
+      </xpath>
+    </template>
+  </data>
+</openerp>