deisy hace 5 años
padre
commit
b92978f48b

+ 1 - 1
__openerp__.py

@@ -33,7 +33,7 @@
     Order""",
     'author': 'ADHOC SA/Eiru',
     'license': 'AGPL-3',
-    'depends': ['sale','account','extra_data_dikasa'],
+    'depends': ['sale','account','extra_data_dikasa','invoice_credit','eiru_payments_invoices'],
     'data': [
         'security/partner_credit_limit_security.xml',
         'views/template.xml',

+ 18 - 31
models/account_invoice.py

@@ -8,33 +8,17 @@ class account_invoice(models.Model):
     _inherit = "account.invoice"
 
     def invoice_validate(self):
-        # self.check_limit()
+        self.check_limit()
         self.check_morosidad()
         return super(account_invoice, self).invoice_validate()
 
     @api.one
     def check_limit(self):
 
-        if self.order_policy == 'prepaid':
+        if self.contado == True:
             return True
 
-        # We sum from all the sale orders that are aproved, the sale order
-        # lines that are not yet invoiced
-        domain = [('order_id.partner_id', '=', self.partner_id.id),
-                  ('invoiced', '=', False),
-                  ('order_id.state', 'not in', ['draft', 'cancel', 'sent'])]
-        order_lines = self.env['sale.order.line'].search(domain)
-        none_invoiced_amount = sum([x.price_subtotal for x in order_lines])
-
-        # We sum from all the invoices that are in draft the total amount
-        domain = [
-            ('partner_id', '=', self.partner_id.id), ('state', '=', 'draft')]
-        draft_invoices = self.env['account.invoice'].search(domain)
-        draft_invoices_amount = sum([x.amount_total for x in draft_invoices])
-
-        available_credit = self.partner_id.credit_limit - \
-            self.partner_id.credit - \
-            none_invoiced_amount - draft_invoices_amount
+        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 credito suficiente.\
@@ -60,15 +44,18 @@ class account_invoice(models.Model):
                     return False
         return True
 
-    @api.multi
-    def save_payments_invoice(self,values):
-        bank_payments_type_id = values['bankPayments']['bank_payments_type_id']
-        payment_type = self.env['res.bank.payments.type'].search([('id', '=', bank_payments_type_id)])
-        partner = self.env['res.partner'].search([('id', '=', values['partnerId'])])
-        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 super(account_invoice, self).save_payments_invoice(values)
+    # @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


+ 2 - 18
models/sale.py

@@ -16,26 +16,10 @@ class sale_order(models.Model):
     @api.one
     def check_limit(self):
 
-        if self.order_policy == 'prepaid':
+        if self.contado == True:
             return True
 
-        # We sum from all the sale orders that are aproved, the sale order
-        # lines that are not yet invoiced
-        domain = [('order_id.partner_id', '=', self.partner_id.id),
-                  ('invoiced', '=', False),
-                  ('order_id.state', 'not in', ['draft', 'cancel', 'sent'])]
-        order_lines = self.env['sale.order.line'].search(domain)
-        none_invoiced_amount = sum([x.price_subtotal for x in order_lines])
-
-        # We sum from all the invoices that are in draft the total amount
-        domain = [
-            ('partner_id', '=', self.partner_id.id), ('state', '=', 'draft')]
-        draft_invoices = self.env['account.invoice'].search(domain)
-        draft_invoices_amount = sum([x.amount_total for x in draft_invoices])
-
-        available_credit = self.partner_id.credit_limit - \
-            self.partner_id.credit - \
-            none_invoiced_amount - draft_invoices_amount
+        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.\

BIN
models/sale.pyc


+ 1 - 1
security/partner_credit_limit_security.xml

@@ -2,7 +2,7 @@
 <openerp>
 <data noupdate="0">
     <record id="credit_config" model="res.groups">
-        <field name="name">Config Credit Limit On partners</field>
+        <field name="name">Permitir cambiar límites de crédito</field>
     </record>
 </data>
 </openerp>

BIN
static/description/icon.png


+ 6 - 0
views/partner_view.xml

@@ -10,6 +10,9 @@
                 <xpath expr="//form[@string='Partners']//field[@name='credit_limit']" position="attributes">
                     <attribute name="readonly">1</attribute>
                 </xpath>
+                <xpath expr="//form[@string='Partners']//field[@name='check_limit']" position="attributes">
+                    <attribute name="readonly">1</attribute>
+                </xpath>
             </field>
         </record>
         <!-- Make not readonly for user_edit_credit_limit  -->
@@ -22,6 +25,9 @@
                 <xpath expr="//form[@string='Partners']//field[@name='credit_limit']" position="attributes">
                     <attribute name="readonly">0</attribute>
                 </xpath>
+                <xpath expr="//form[@string='Partners']//field[@name='check_limit']" position="attributes">
+                    <attribute name="readonly">0</attribute>
+                </xpath>
             </field>
         </record>
     </data>