ソースを参照

Módulo que premite colocar un limite de crédito a cada cliente y no permitir realizar las compras.

sebas 4 年 前
コミット
c55660cf33
4 ファイル変更31 行追加18 行削除
  1. 3 2
      __openerp__.py
  2. 6 5
      models/account_invoice.py
  3. 12 11
      models/sale.py
  4. 10 0
      views/partner_credito_limite.xml

+ 3 - 2
__openerp__.py

@@ -19,7 +19,7 @@
 #
 ##############################################################################
 {
-    'name': 'Validaciones ',
+    'name': 'Limite de crédito en cliente',
     'version': '8.0.1.1.0',
     'summary': '',
     'description': """
@@ -32,12 +32,13 @@
     'depends': [
         'sale',
         'purchase',
+        'credito_cash_check',
         'account',
         'eiru_payments_invoices'],
     'data': [
         'views/template.xml',
         'views/partner_view.xml',
-
+        'views/partner_credito_limite.xml',
         ],
     'installable': True,
 }

+ 6 - 5
models/account_invoice.py

@@ -21,11 +21,12 @@ class account_invoice(models.Model):
         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
+            if not self.user_has_groups('partner_credito_limite.groups_partner_credito_limite'):
+                msg = 'No se puede confirmar el Pedido ya que el cliente no tiene crédito suficiente.\
+                    Pruebe marcar la opción "Contado" o pedir autorización para poder realizar la venta.'
+                raise Warning(_(msg))
+                return False
+            return True
 
     # @api.multi
     # def check_morosidad(self):

+ 12 - 11
models/sale.py

@@ -16,17 +16,18 @@ class sale_order(models.Model):
     @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
+            if self.contado == True:
+                return True
+
+            available_credit = self.partner_id.credit_limit - self.partner_id.credit
+
+            if self.amount_total > available_credit:
+                if not self.user_has_groups('partner_credito_limite.groups_partner_credito_limite'):
+                    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):

+ 10 - 0
views/partner_credito_limite.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="groups_partner_credito_limite" model="res.groups">
+            <field name="name">Permitir vender sobre limite de credito</field>
+            <field name="category_id" ref="base.module_category_extra" />
+        </record>
+
+      </data>
+  </openerp>