~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to partner_credit_limit/sale.py

  • Committer: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
##############################################################################
23
23
 
24
24
import time
25
 
import netsvc
26
 
from osv import fields, osv
 
25
import openerp.netsvc as netsvc
 
26
from openerp.osv import osv, fields
27
27
from mx import DateTime
28
28
from tools import config
29
 
from tools.translate import _
30
 
 
31
 
class sale_order(osv.osv):
 
29
from openerp.tools.translate import _
 
30
 
 
31
 
 
32
 
 
33
class sale_order(osv.Model):
32
34
    _inherit = "sale.order"
33
35
 
34
36
    def check_limit(self, cr, uid, ids, context={}):
36
38
        partner = so.partner_id
37
39
 
38
40
        moveline_obj = self.pool.get('account.move.line')
39
 
        movelines = moveline_obj.search(cr, uid, [('partner_id', '=', partner.id),('account_id.type', 'in', ['receivable', 'payable']), ('state', '<>', 'draft'), ('reconcile_id', '=', False)])
 
41
        movelines = moveline_obj.search(cr, uid, [('partner_id', '=', partner.id), ('account_id.type', 'in', [
 
42
                                        'receivable', 'payable']), ('state', '<>', 'draft'), ('reconcile_id', '=', False)])
40
43
        movelines = moveline_obj.browse(cr, uid, movelines)
41
44
 
42
45
        debit, credit = 0.0, 0.0
43
46
        debit_maturity, credit_maturity = 0.0, 0.0
44
47
        #~ #~
45
48
        for line in movelines:
46
 
            if line.date_maturity < time.strftime('%Y-%m-%d') and line.date_maturity <> False:
 
49
            if line.date_maturity < time.strftime('%Y-%m-%d') and line.date_maturity != False:
47
50
                credit_maturity += line.debit
48
51
                debit_maturity += line.credit
49
52
            credit += line.debit
53
56
        saldo_maturity = credit_maturity - debit_maturity
54
57
 
55
58
        if (saldo_maturity + so.amount_total) > partner.credit_maturity_limit or (saldo + so.amount_total) > partner.credit_limit:
56
 
            if not partner.over_credit :
 
59
            if not partner.over_credit:
57
60
                if (saldo + so.amount_total) > partner.credit_limit and partner.credit_limit > 0.00:
58
 
                    msg = _('Can not validate the Sale Order because it has exceeded the credit limit \nCredit Limit: %s \nCheck the credit limits on Partner')%(partner.credit_limit)
 
61
                    msg = _('Can not validate the Sale Order because it has exceeded the credit limit \nCredit Limit: %s \nCheck the credit limits on Partner') % (
 
62
                        partner.credit_limit)
59
63
                    #'Can not validate Invoice because Total Invoice is greater than credit_limit: %s\nCheck Partner Accounts or Credit Limits !'%(partner.credit_limit)
60
64
                    raise osv.except_osv(_('Credit Over Limits !'), (msg))
61
65
                    return False
62
66
            else:
63
 
                self.pool.get('res.partner').write(cr, uid, [partner.id], {'credit_limit':credit - debit + so.amount_total})
 
67
                self.pool.get('res.partner').write(cr, uid, [partner.id], {
 
68
                                                   'credit_limit': credit - debit + so.amount_total})
64
69
 
65
70
            if not partner.maturity_over_credit:
66
71
                if (saldo_maturity + so.amount_total) > partner.credit_maturity_limit and partner.credit_maturity_limit > 0.00:
67
72
                    #~ msg = 'Can not validate Invoice, Total mature due Amount %s as on %s !\nCheck Partner Accounts or Credit Limits !' % (credit - debit, time.strftime('%Y-%m-%d'))
68
 
                    msg = _('Can not validate the Sale Order because it has exceeded the credit limit up to date: %s \nMaturity Amount: %s \nMaturity Credit Limit: %s \nCheck the credit limits on Partner')%(time.strftime('%Y-%m-%d'), saldo_maturity, partner.credit_maturity_limit)
 
73
                    msg = _('Can not validate the Sale Order because it has exceeded the credit limit up to date: %s \nMaturity Amount: %s \nMaturity Credit Limit: %s \nCheck the credit limits on Partner') % (
 
74
                        time.strftime('%Y-%m-%d'), saldo_maturity, partner.credit_maturity_limit)
69
75
 
70
 
                    raise osv.except_osv(_('Maturity Credit Over Limits !'), (msg))
 
76
                    raise osv.except_osv(_(
 
77
                        'Maturity Credit Over Limits !'), (msg))
71
78
                    return False
72
79
                else:
73
80
                    return True
74
81
            else:
75
 
                self.pool.get('res.partner').write(cr, uid, [partner.id], {'credit_maturity_limit':credit_maturity - debit_maturity + so.amount_total})
 
82
                self.pool.get('res.partner').write(cr, uid, [partner.id], {
 
83
                                                   'credit_maturity_limit': credit_maturity - debit_maturity + so.amount_total})
76
84
                return True
77
85
        else:
78
86
 
79
87
            return True
80
 
sale_order()