123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- # -*- coding: utf-8 -*-
- from openerp.http import request
- '''
- ██████ █████ ███ ██ ██ ██ ███████ ████████ █████ ████████ ███████ ███ ███ ███████ ███ ██ ████████
- ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██
- ██████ ███████ ██ ██ ██ █████ ███████ ██ ███████ ██ █████ ██ ████ ██ █████ ██ ██ ██ ██
- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
- ██████ ██ ██ ██ ████ ██ ██ ██ ███████ ██ ██ ██ ██ ███████ ██ ██ ███████ ██ ████ ██
- '''
- _MODEL = 'account.bank.statement'
- '''
- ██████ ███████ ████████
- ██ ██ ██
- ██ ███ █████ ██
- ██ ██ ██ ██
- ██████ ███████ ██
- '''
- def search_account_bank_statement(statementId):
- casbox= []
- statement = request.env['account.bank.statement'].browse(statementId)
- if (statement):
- casbox = {
- 'id': statement.id,
- 'name': statement.name,
- 'accountId': statement.journal_id.internal_account_id.id,
- 'journalId': statement.journal_id.id,
- 'balanceEnd': statement.balance_end
- }
- return casbox
- '''
- ██████ ██████ ███████ █████ ████████ ███████
- ██ ██ ██ ██ ██ ██ ██ ██
- ██ ██████ █████ ███████ ██ █████
- ██ ██ ██ ██ ██ ██ ██ ██
- ██████ ██ ██ ███████ ██ ██ ██ ███████ ██ Account Bank Statement
- '''
- def create_account_bank_statement(data):
- from account_bank_statement_config import get_bank_statement_config
- config = get_bank_statement_config()
- if (not config):
- return {
- 'state': False,
- 'message': 'No existe configuración de caja'
- }
- domain = [('journal_id', '=', data['journal_id']),('type_statement', '=', data['type_statement']),('user_id', '=', data['user_id']),('state', '=', 'open')]
- statementVerify = request.env[_MODEL].search(domain)
- if ((not config.statement_open_config) and (statementVerify)):
- return {
- 'state': False,
- 'message': 'Ya existe una caja abierta con los mismos parámetros'
- }
- ''' Create CashBox '''
- statement = request.env[_MODEL].sudo().create(data)
- if(not statement):
- return {
- 'state': False,
- 'message': 'No fue posible crear la caja'
- }
- ''' Open cashBox '''
- openStatement = statement.sudo().button_open()
- if (not openStatement):
- return {
- 'state': False,
- 'message': 'No fue posible abrir la caja '
- }
- return {
- 'state': openStatement,
- 'message': 'Caja creada con éxito',
- 'data' : {
- 'id': statement.id,
- 'name': statement.name,
- 'date': statement.date,
- 'state': statement.state,
- 'balanceEnd': statement.balance_end,
- 'user': {
- 'id': statement.user_id.id,
- 'name': statement.user_id.name,
- 'displayName': statement.user_id.display_name
- },
- 'userSession': request.env.user.id,
- 'journal': {
- 'id': statement.journal_id.id,
- 'name': statement.journal_id.name,
- 'displayName': statement.journal_id.display_name,
- 'code': statement.journal_id.code,
- 'cashControl': statement.journal_id.cash_control,
- 'type': statement.journal_id.type,
- 'currency': {
- 'id': statement.journal_id.currency.id,
- 'name': statement.journal_id.currency.name,
- 'displayName': statement.journal_id.currency.display_name
- }
- },
- 'line': [{
- 'id': line.id,
- 'date': line.date,
- 'name': line.name,
- 'ref': line.ref,
- 'amount': line.amount,
- 'patner':{
- 'id': line.partner_id.id,
- 'name': line.partner_id.name,
- 'displayName': line.partner_id.display_name
- },
- } for line in statement.line_ids],
- 'typeStatement': {
- 'id': statement.type_statement.id,
- 'name': statement.type_statement.name,
- 'code': statement.type_statement.code
- },
- 'currency':{
- 'id': statement.currency.id,
- 'name': statement.currency.display_name,
- 'base': statement.currency.base,
- 'symbol': statement.currency.symbol,
- 'position': statement.currency.position,
- 'rateSilent': statement.currency.rate_silent,
- 'decimalSeparator': statement.currency.decimal_separator,
- 'decimalPlaces': statement.currency.decimal_places,
- 'thousandsSeparator': statement.currency.thousands_separator
- }
- }
- }
- '''
- ██████ ██ ██████ ███████ ██ ███ ██ ██████
- ██ ██ ██ ██ ██ ██ ████ ██ ██
- ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ███
- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
- ██████ ███████ ██████ ███████ ██ ██ ████ ██████ bank Statement
- '''
- def closing_statement(data):
- from account_bank_statement_line import create_statement_line
- from cashbox_confirm import get_cashbox_statement_confirm, create_cashbox_statement_confirm, write_cashbox_statement_confirm
- from server_datetime import get_date
- lineDifference = []
- lineclosing = []
- statement = request.env[_MODEL].browse(data['statementId'])
- if (not statement):
- return {
- 'state': False,
- 'message': 'No fue posible localizar la caja.'
- }
- amountStatement = statement.balance_end or 0.0
- ''' Registrar Diferencia entre saldos '''
- if (statement.balance_end != data['amount']):
- lineDifference = create_statement_line({
- 'statement_id': statement.id,
- 'name': "Diferencia entre valor teórico de cierre y valor real de cierre.",
- 'amount': data['amount'] - statement.balance_end,
- 'ref': 'AJUSTE DE CIERRE',
- 'account_id': statement.journal_id.internal_account_id.id,
- 'journal_id': statement.journal_id.id,
- # 'is_deleted': True
- })
- if (not lineDifference):
- return {
- 'state': False,
- 'message': 'No fue posible registrar el ajuste de cierre.'
- }
- ''' Resgitro de saldo '''
- if (statement.balance_end != 0):
- lineclosing = create_statement_line({
- 'statement_id': statement.id,
- 'name': "Registro de saldo para próxima apertura.",
- 'amount': - statement.balance_end if (statement.balance_end > 0) else abs(statement.balance_end),
- 'ref': 'CIERRE DE CAJA',
- 'account_id': statement.journal_id.internal_account_id.id,
- 'journal_id': statement.journal_id.id,
- # 'is_deleted': True
- })
- if (not lineclosing):
- return {
- 'state': False,
- 'message': 'No fue posible registrar el cierre de caja.'
- }
- amountNexOpen = abs(lineclosing.amount) if (lineclosing.amount < 0 ) else - (lineclosing.amount)
- # import web_pdb; web_pdb.set_trace()
- ''' Registro de Cierre de caja '''
- statementConfirm = get_cashbox_statement_confirm([('statement_id.id', '=', statement.id)])
- cashboxConfirm = {
- 'name': "CIERRE DE CAJA /"+str(statement.name),
- 'date': get_date(),
- 'ref': data['description'],
- 'statement_id': statement.id,
- 'user_statement': statement.user_id.id,
- 'user_confirm': request.env.user.id,
- 'journal_id' : statement.journal_id.id,
- 'amount_statement': amountStatement,
- 'amount_real': data['amount'],
- 'line_difference': lineDifference.id if (lineDifference) else '',
- 'amount_difference': lineDifference.amount if (lineDifference) else 0.0,
- 'line_next_open': lineclosing.id if(lineclosing) else '',
- 'amount_next_open': amountNexOpen if(lineclosing) else 0.0,
- 'state_avaliable': True if(lineclosing and abs(lineclosing.amount) > 0) else False,
- }
- confirm = create_cashbox_statement_confirm(cashboxConfirm) if (not statementConfirm) else write_cashbox_statement_confirm(statementConfirm.id, cashboxConfirm)
- if (not confirm):
- return {
- 'state': False,
- 'message': 'No fue posible crear el cierre de caja'
- }
- response = statement.button_confirm_cash()
- if (not response):
- return {
- 'state': False,
- 'message': 'No fue posible cerrar la caja'
- }
- return {
- 'state': True,
- 'message': 'Cierre de caja, realizada con éxito.'
- }
|