From f9e1202d8711c4c9a522866876ae63f5ec2506b5 Mon Sep 17 00:00:00 2001 From: SHEREEF PT Date: Tue, 7 Nov 2017 10:11:55 +0530 Subject: [PATCH] [RMV] Print Console Removed --- account_limit/models/account.py | 1 - account_limit/models/account.py~ | 113 +++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 account_limit/models/account.py~ diff --git a/account_limit/models/account.py b/account_limit/models/account.py index 7295d2026..edb7287fc 100644 --- a/account_limit/models/account.py +++ b/account_limit/models/account.py @@ -30,7 +30,6 @@ class AccountAccount(models.Model): @api.multi def get_credit_debit_balance(self): - print "get_credit_debit_balance", self for obj in self: credit = 0 debit = 0 diff --git a/account_limit/models/account.py~ b/account_limit/models/account.py~ new file mode 100644 index 000000000..7295d2026 --- /dev/null +++ b/account_limit/models/account.py~ @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author: Nikhil krishnan() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# 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 LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +from odoo import fields, api, _, models +from odoo.exceptions import Warning + + +class AccountAccount(models.Model): + _inherit = 'account.account' + + @api.multi + def get_credit_debit_balance(self): + print "get_credit_debit_balance", self + for obj in self: + credit = 0 + debit = 0 + account_lines = self.env['account.move.line'].search([('account_id', '=', obj.id)]) + for line in account_lines: + credit += line.credit + debit += line.debit + obj.credit = credit + obj.debit = debit + obj.balance = debit - credit + + credit = fields.Float(string='Credit', compute='get_credit_debit_balance') + debit = fields.Float(string='Debit', compute='get_credit_debit_balance') + balance = fields.Float(string='Balance', compute='get_credit_debit_balance') + account_credit_limit = fields.Float(string='Credit Limit', Help="Credit Limit for this particular Account.") + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.model + def create(self, vals): + credit = 0 + debit = 0 + if "line_ids" in vals.keys(): + for line in vals['line_ids']: + if line[2]['credit']: + account = self.env['account.account'].browse(line[2]['account_id']) + account_lines = self.env['account.move.line'].search([('account_id', '=', account.id)]) + for lines in account_lines: + credit += lines.credit + debit += lines.debit + if account.account_credit_limit: + if (credit+line[2]['credit'] - debit) > account.account_credit_limit: + raise Warning(_('Limit will Exceed .! \n Making this transaction will exceed the limit ' + 'defined for " %s " account') % account.name) + result = super(AccountMove, self).create(vals) + return result + + @api.multi + def write(self, vals): + if "line_ids" in vals.keys(): + for line in vals['line_ids']: + account_lines = self.env['account.move.line'].browse(line[1]) + if line[2]: + if 'account_id' in line[2]: + if line[2]['account_id']: + account = self.env['account.account'].browse(line[2]['account_id']) + if account.account_credit_limit: + if 'debit' in line[2]: + new_debit = line[2]['debit'] + else: + new_debit = account_lines.debit + if 'credit' in line[2]: + new_credit = line[2]['credit'] + else: + new_credit = account_lines.credit + if (account.credit + new_credit - new_debit - account.debit) > account.account_credit_limit: + raise Warning( + _('Limit will Exceed .! \n Making this transaction will exceed the limit ' + 'defined for " %s " account') % account.name) + else: + account = account_lines.account_id + if account.account_credit_limit: + if 'debit' in line[2]: + if line[2]['debit']: + old_debit = account_lines.debit + if (account.credit - line[2]['debit'] - account.debit + old_debit) > account.account_credit_limit: + raise Warning( + _('Limit will Exceed .! \n Making this transaction will exceed the limit ' + 'defined for " %s " account') % account.name) + if 'credit' in line[2]: + if line[2]['credit']: + old_credit = account_lines.credit + if (account.credit+line[2]['credit']-account.debit-old_credit) > account.account_credit_limit: + raise Warning( + _('Limit will Exceed .! \n Making this transaction will exceed the limit ' + 'defined for " %s " account') % account.name) + result = super(AccountMove, self).write(vals) + return result