123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, tools, api
- from datetime import datetime
- from pytz import timezone
- DATE_FORMAT = '%Y-%m-%d'
- class AccountBankStatementUtility(models.Model):
- _inherit = 'account.bank.statement'
- '''
- get_account_bank_statement_utility
- '''
- @api.model
- def get_account_bank_statement_utility(self, id):
- '''
- Get Account Bank Statement
- :param : id: id account bank statement,
- :return : Object Account bank statement + Amount(account Bank statement line)
- '''
- decimal_precision = self.env['decimal.precision'].precision_get('Account')
- bankStatement = self.env['account.bank.statement'].browse(id)
- if (not bankStatement):
- return False
- accountStatement = []
- amount = 0.0
- for line in bankStatement.line_ids:
- amount += line.amount
- if (bankStatement.balance_start > 0):
- amount += bankStatement.balance_start
- accountStatement.append({
- 'id': bankStatement.id,
- 'name': bankStatement.name,
- 'date': bankStatement.date,
- 'journalId': bankStatement.journal_id.id,
- 'periodId': bankStatement.period_id.id,
- 'userId': bankStatement.user_id.id,
- 'userName': bankStatement.user_id.name,
- 'typeStatement': bankStatement.type_statement.id,
- 'typeStatementName': bankStatement.type_statement.name,
- 'state': bankStatement.state,
- 'amount': round(amount,decimal_precision),
- 'currencystatement': {
- 'id': bankStatement.currency.id,
- 'symbol': bankStatement.currency.symbol,
- 'rate': bankStatement.currency.rate,
- 'thousandsSeparator': bankStatement.currency.thousands_separator,
- 'decimalSeparator': bankStatement.currency.decimal_separator,
- 'decimalPlaces': bankStatement.currency.decimal_places,
- 'position': bankStatement.currency.position,
- },
- })
- return accountStatement
- @api.model
- def get_account_journal_utility(self,id):
- bankStatement = self.env['account.bank.statement'].browse(id)
- if (not bankStatement):
- return False
- domain = [('active', '=', True), ('type', 'in', ['bank', 'cash']), ('id', 'in', [bankStatement.journal_id.id])];
- accountJournal = self.env['account.journal'].search(domain)
- journalUtility = []
- for journal in accountJournal:
- domainStatment = [('id','!=',bankStatement.id),('journal_id','in',[journal.id])]
- # domainStatment = [('id','!=',bankStatement.id) ,('journal_id','in',[journal.id]),('date','=',bankStatement.date),('period_id','=',bankStatement.period_id.id)]
- if (journal.type == 'cash'):
- domainStatment.append(('state','=', 'open'))
- if (journal.type == 'bank'):
- domainStatment.append(('state','!=','confirm'))
- statementJournal = []
- statement = self.env['account.bank.statement'].search(domainStatment)
- for statementOpen in statement:
- statementJournal.append({
- 'id': statementOpen.id,
- 'journalId': statementOpen.journal_id.id,
- 'date': statementOpen.date,
- 'typeStatementId': statementOpen.type_statement.id,
- 'typeStatementName': statementOpen.type_statement.name,
- 'userId': statementOpen.user_id.id,
- 'userName': statementOpen.user_id.name,
- 'name': statementOpen.name,
- 'state': statementOpen.state,
- 'statementname': statementOpen.name+" / "+statementOpen.user_id.name
- })
- journalUtility.append({
- 'id': journal.id,
- 'name': journal.name,
- 'code': journal.code,
- 'type': journal.type,
- 'currencyId': journal.currency.id,
- 'statementJournal': statementJournal
- })
- return journalUtility
- '''
- Get User Login
- '''
- @api.model
- def eiru_transfers_get_user(self):
- return [{
- 'id': user.id,
- 'name': user.name
- } for user in self.env.user]
- @api.model
- def eiru_transfers_get_chas_box_transfer(self, id):
- return [{
- 'id': transfer.id,
- 'name': transfer.name,
- 'amount': transfer.amount,
- 'ref': transfer.ref,
- 'date': transfer.date,
- 'outputStatement': {
- 'id': transfer.output_statement.id,
- 'name': transfer.output_statement.name,
- 'typeJournal': transfer.output_statement.journal_id.type,
- 'state': transfer.output_statement.state,
- 'date': transfer.output_statement.date,
- 'userId': transfer.output_statement.user_id.id,
- 'currency': {
- 'symbol': transfer.output_statement.currency.symbol,
- 'thousandsSeparator': transfer.output_statement.currency.thousands_separator,
- 'decimalSeparator': transfer.output_statement.currency.decimal_separator,
- 'decimalPlaces': transfer.output_statement.currency.decimal_places,
- }
- },
- 'inputStatement': {
- 'id': transfer.input_statement.id,
- 'name': transfer.input_statement.name,
- 'state': transfer.input_statement.state,
- 'typeJournal': transfer.input_statement.journal_id.type,
- 'date': transfer.input_statement.date,
- 'userId': transfer.input_statement.user_id.id,
- 'currency': {
- 'symbol': transfer.input_statement.currency.symbol,
- 'thousandsSeparator': transfer.input_statement.currency.thousands_separator,
- 'decimalSeparator': transfer.input_statement.currency.decimal_separator,
- 'decimalPlaces': transfer.input_statement.currency.decimal_places,
- }
- },
- 'outputLine': {
- 'id': transfer.output_line.id,
- 'statementID': transfer.output_line.statement_id.id,
- },
- 'inputLine': {
- 'id': transfer.input_line.id,
- 'statementID': transfer.input_line.statement_id.id,
- }
- } for transfer in self.env['cash.box.transfer'].search(['|', ('output_statement.id','=',id), ('input_statement.id','=',id)])]
- '''
- _____ __
- |_ _| __ __ _ _ __ ___ / _| ___ _ __ ___
- | || '__/ _` | '_ \/ __| |_ / _ \ '__/ __|
- | || | | (_| | | | \__ \ _| __/ | \__ \
- |_||_| \__,_|_| |_|___/_| \___|_| |___/
- '''
- '''
- Get Account Bank Statement
- '''
- def _get_statement_transfer(self,id):
- return self.env['account.bank.statement'].browse(id)
- '''
- Get Account Journal
- '''
- def _get_journal_transfer(self, id):
- return self.env['account.journal'].browse(id)
- '''
- Create Line statement.
- '''
- def _create_statement_line_transfer(self, statement, name, amount, ref):
- statementLine = {
- 'statement_id': statement.id,
- 'name': name,
- 'amount': amount ,
- 'ref': ref,
- 'account_id': statement.journal_id.internal_account_id.id,
- 'journal_id': statement.journal_id.id,
- 'is_deleted': True
- }
- line = self.env['account.bank.statement.line'].create(statementLine)
- return line
- '''
- Create cash box transfer
- '''
- def _create_cash_box_transfer(self, ref, amount, lineInput, lineOutput):
- cash = {
- 'name': "TRANSFERENCIA %s a %s" %((lineOutput.statement_id.name),(lineInput.statement_id.name)),
- 'amount': amount,
- 'ref': ref,
- 'input_line': lineInput.id,
- 'output_line': lineOutput.id,
- 'input_statement': lineInput.statement_id.id,
- 'output_statement': lineOutput.statement_id.id,
- 'date': lineOutput.date
- }
- return self.env['cash.box.transfer'].create(cash)
- '''
- Create Line statement Transfer
- '''
- @api.model
- def statement_complet_transfers(self, values):
- statementOrigin = self._get_statement_transfer(values['statementOriginId'])
- if (not statementOrigin):
- return False
- statementDestiny = self._get_statement_transfer(values['statementDestinyId'])
- if (not statementDestiny):
- return False
- accountJournal = self._get_journal_transfer(values['journalID'])
- if (not accountJournal):
- return False
- # output
- name = "TRANSFERENCIA/"+str(statementDestiny.name)
- statementOutput = self._create_statement_line_transfer(statementOrigin, name,(-values['amountTransfer']), values['refTransfer'])
- if (not statementOutput):
- return False
- # input
- name = "TRANSFERENCIA/"+str(statementOrigin.name)
- statementInput = self._create_statement_line_transfer(statementDestiny, name, abs(values['amountTransfer']), values['refTransfer'])
- if (not statementInput):
- return False
- cash_box_transfer = self._create_cash_box_transfer(values['refTransfer'], abs(values['amountTransfer']), statementInput, statementOutput)
- if (not cash_box_transfer):
- return False
- return True
- '''
- _ _ _ _ _ _____ __
- | | | |_ __ | (_)_ __ | | __ |_ _| __ __ _ _ __ ___ / _| ___ _ __
- | | | | '_ \| | | '_ \| |/ / | || '__/ _` | '_ \/ __| |_ / _ \ '__|
- | |_| | | | | | | | | | < | || | | (_| | | | \__ \ _| __/ |
- \___/|_| |_|_|_|_| |_|_|\_\ |_||_| \__,_|_| |_|___/_| \___|_|
- '''
- '''
- Get Cash Box Transfer
- '''
- def _get_cash_box_transfer(self, id):
- return self.env['cash.box.transfer'].browse(id)
- '''
- Get timezone
- '''
- def get_timezone(self):
- tz_name = self._context.get('tz') or self.env.user.tz
- return timezone(tz_name)
- '''
- Get server date
- '''
- def get_server_datetime(self):
- return datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
- '''
- Get Statement Line
- '''
- def _get_statement_Line(self, id):
- return self.env['account.bank.statement.line'].browse(id)
- '''
- writer Line Statement
- '''
- def _write_statement_line_transfer(self, line):
- return line.write({
- 'is_deleted': False
- })
- '''
- Unlink Line Statement
- '''
- def _unlink_statement_line_transfer(self, line):
- return line.unlink()
- '''
- Write cash box transfer
- '''
- def _write_cash_box_transfer(self, casbox, message, user):
- return casbox.write({
- 'message_deleted': message,
- 'active': False,
- 'write_uid': user.id
- })
- '''
- unlink Initial
- '''
- @api.model
- def unlink_transfer(self, values):
- ### user
- user = self.env.user
- ### date server
- date_server = self.get_server_datetime()
- ### account Statement
- statement = self._get_statement_transfer(values['statementId'])
- if (not statement):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- ### Transferencia
- cashBoxTransfer = self._get_cash_box_transfer(values['transferId'])
- if (not cashBoxTransfer):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- ### Line output
- lineOutput = self._get_statement_Line(cashBoxTransfer.output_line.id)
- if (not lineOutput):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- if (lineOutput.statement_id.state == 'confirm'):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación, por que la caja de origen ya fue cerrada"
- }
- ### Line Input
- lineInput = self._get_statement_Line(cashBoxTransfer.input_line.id)
- if (not lineInput):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- if (lineInput.statement_id.state == 'confirm'):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación por que la caja destino ya fue cerrada"
- }
- ## updtae
- writeOutput = self._write_statement_line_transfer(lineOutput)
- ## unlink
- unlinkOutpu = self._unlink_statement_line_transfer(lineOutput)
- if (not unlinkOutpu):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación, error al eliminar la transferencia"
- }
- ## Update
- writeInput = self._write_statement_line_transfer(lineInput)
- ## Unlink
- unlinkInput = self._unlink_statement_line_transfer(lineInput)
- if (not unlinkInput):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación, error al eliminar la transferencia"
- }
- message = values['comment']+" \nEliminado por la caja "+str(statement.name)+" y por Usuario "+str(user.name)+" en "+str(date_server)
- writeTransfer = self._write_cash_box_transfer(cashBoxTransfer, message, user)
- if (not writeTransfer):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación"
- }
- return { 'state': True,
- 'message': 'Operación realizada con éxito'
- }
- '''
- ____ ____ ___ ___ _
- / ___|__ _ ___| __ ) _____ __ |_ _|_ __ / _ \ _ _| |_
- | | / _` / __| _ \ / _ \ \/ / | || '_ \ _____ | | | | | | | __|
- | |__| (_| \__ \ |_) | (_) > < | || | | | |_____| | |_| | |_| | |_
- \____\__,_|___/____/ \___/_/\_\ |___|_| |_| \___/ \__,_|\__|
- '''
- '''
- GET CashBox In
- '''
- @api.model
- def eiru_get_cash_box_in(self, id):
- return [{
- 'id': box_in.id,
- 'name': box_in.name,
- 'amount': box_in.amount,
- 'ref': box_in.ref,
- 'date': box_in.date,
- 'type': 'in',
- 'statement': {
- 'id': box_in.statement_id.id,
- 'name': box_in.statement_id.name,
- 'state': box_in.statement_id.state,
- 'typeJournal': box_in.statement_id.journal_id.type,
- 'date': box_in.statement_id.date,
- 'userId': box_in.statement_id.user_id.id,
- 'currency': {
- 'symbol': box_in.statement_id.currency.symbol,
- 'thousandsSeparator': box_in.statement_id.currency.thousands_separator,
- 'decimalSeparator': box_in.statement_id.currency.decimal_separator,
- 'decimalPlaces': box_in.statement_id.currency.decimal_places,
- }
- },
- 'statementLine': {
- 'id': box_in.line_id.id
- }
- } for box_in in self.env['cash.box.in'].search([('statement_id.id', '=', id)])]
- '''
- GET CashBox out
- '''
- @api.model
- def eiru_get_cash_box_out(self, id):
- return [{
- 'id': box_out.id,
- 'name': box_out.name,
- 'amount': box_out.amount,
- 'ref': box_out.ref,
- 'date': box_out.date,
- 'type': 'out',
- 'statement': {
- 'id': box_out.statement_id.id,
- 'name': box_out.statement_id.name,
- 'state': box_out.statement_id.state,
- 'typeJournal': box_out.statement_id.journal_id.type,
- 'date': box_out.statement_id.date,
- 'userId': box_out.statement_id.user_id.id,
- 'currency': {
- 'symbol': box_out.statement_id.currency.symbol,
- 'thousandsSeparator': box_out.statement_id.currency.thousands_separator,
- 'decimalSeparator': box_out.statement_id.currency.decimal_separator,
- 'decimalPlaces': box_out.statement_id.currency.decimal_places,
- }
- },
- 'statementLine': {
- 'id': box_out.line_id.id
- }
- } for box_out in self.env['cash.box.out'].search([('statement_id.id', '=', id)])]
- '''
- Create Statement Line
- '''
- def _create_statement_line_input_outup(self, statement,ref,amount,type,name):
- statementLine = {
- 'statement_id': statement.id,
- 'name': name,
- 'amount': type in ('input') and amount or -amount,
- 'ref': ref,
- 'account_id': statement.journal_id.internal_account_id.id,
- 'journal_id': statement.journal_id.id,
- 'is_deleted': True
- }
- line = self.env['account.bank.statement.line'].create(statementLine)
- return line
- '''
- Create cashBox input
- '''
- def create_cash_box_in_out(self, line, amount, ref, name, type):
- cash = {
- 'name': "%s %s" %((name),(line.statement_id.name)),
- 'amount': amount,
- 'ref': ref,
- 'date': line.date,
- 'line_id': line.id,
- 'statement_id': line.statement_id.id,
- }
- if (type =='input'):
- return self.env['cash.box.in'].create(cash)
- else:
- return self.env['cash.box.out'].create(cash)
- '''
- Create casbox input/output
- '''
- @api.model
- def create_cash_box_input_output(self, values):
- statement = self._get_statement_transfer(values['statementId'])
- if (not statement):
- return False
- name = values['type'] in ('input') and 'Entrada de Dinero' or 'Salida de Dinero'
- lineStatement = self._create_statement_line_input_outup(statement, values['ref'], values['amount'], values['type'], name)
- if (not lineStatement):
- return False
- casBox = self.create_cash_box_in_out(lineStatement, values['amount'], values['ref'], name, values['type'])
- if (not casBox):
- return False
- return {
- 'state': True
- }
- '''
- _ _ _ _ _ _ _ _ __ _
- | | | |_ __ | (_)_ __ | | __ ___ __ _ ___| |__ | |__ _____ __ (_)_ __ / /__ _ _| |_
- | | | | '_ \| | | '_ \| |/ / / __/ _` / __| '_ \| '_ \ / _ \ \/ / | | '_ \ / / _ \| | | | __|
- | |_| | | | | | | | | | < | (_| (_| \__ \ | | | |_) | (_) > < | | | | |/ / (_) | |_| | |_
- \___/|_| |_|_|_|_| |_|_|\_\ \___\__,_|___/_| |_|_.__/ \___/_/\_\ |_|_| |_/_/ \___/ \__,_|\__|
- '''
- '''
- get Cash box in - out
- '''
- def _get_cash_box_in_out(self, id, type):
- if (type == 'in'):
- return self.env['cash.box.in'].browse(id)
- if (type == 'out'):
- return self.env['cash.box.out'].browse(id)
- '''
- Unlink cash box in/out
- '''
- @api.model
- def unlink_cashbox_in_out(self, values):
- ### user
- user = self.env.user
- ### date server
- date_server = self.get_server_datetime()
- ### account Statement
- statement = self._get_statement_transfer(values['statementId'])
- if (not statement):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- ### cas box
- cashBox = self._get_cash_box_in_out(values['cashboxID'], values['type'])
- if (not cashBox):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- ### Line statement
- lineStatement = self._get_statement_Line(cashBox.line_id.id)
- if (not lineStatement):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación."
- }
- ## updtae line
- writelinet = self._write_statement_line_transfer(lineStatement)
- ## unlink line
- unlinkline = self._unlink_statement_line_transfer(lineStatement)
- if (not unlinkline):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación, error al eliminar la transferencia"
- }
- message = values['message']+" \nEliminado por la caja "+str(statement.name)+" y por Usuario "+str(user.name)+" en "+str(date_server)
- writeTransfer = self._write_cash_box_transfer(cashBox, message, user)
- if (not writeTransfer):
- return {
- 'state' : False,
- 'message': "No se pudo completar la operación"
- }
- return { 'state': True,
- 'message': 'Operación realizada con éxito'
- }
- '''
- ____ _ _ _ ___
- / ___|| |_ __ _| |_ ___ _ __ ___ ___ _ __ | |_ / _ \ _ __ ___ _ __
- \___ \| __/ _` | __/ _ \ '_ ` _ \ / _ \ '_ \| __| | | | | '_ \ / _ \ '_ \
- ___) | || (_| | || __/ | | | | | __/ | | | |_ | |_| | |_) | __/ | | |
- |____/ \__\__,_|\__\___|_| |_| |_|\___|_| |_|\__| \___/| .__/ \___|_| |_|
- |_|
- '''
- '''
- Get Statement Open
- '''
- @api.model
- def get_account_bank_statement_open(self,id):
- statement = self._get_statement_transfer(id)
- if (not statement):
- return False
- return [{
- 'id': open.id,
- 'name': open.name
- } for open in self.env['account.bank.statement'].search([('journal_id.id', '=',statement.journal_id.id),('type_statement.id', '=', statement.type_statement.id),('user_id.id', '=', statement.user_id.id),('state', '=', 'open')])]
- '''
- Open cashBox
- '''
- @api.model
- def account_bank_statement_open_cashbox(self, id):
- statement = self._get_statement_transfer(id)
- return statement.button_open()
- @api.model
- def account_bank_statement_open(self, id):
- statement = self._get_statement_transfer(id)
- cashBoxConfirm = self._get_cashbox_statement_confirm(statement)
- for casBox in cashBoxConfirm:
- name = "SALDO ANTERIOR /"+str(casBox.statement_id.name)
- lineTransfer = self._create_statement_line_transfer(statement, name, (casBox.amount_next_open), 'Apertura')
- # lineTransfer = self._create_statement_line_transfer(statement, name, abs(casBox.amount_next_open), 'Apertura')
- if (not lineTransfer):
- return {
- 'state': False,
- 'message': "Error al registrar el saldo anterior."
- }
- confirmCasBox = self.env['cashbox.statement.confirm'].browse(casBox.id)
- values = {
- 'statement_open': statement.id,
- 'line_open': lineTransfer.id,
- 'state_avaliable': False
- }
- confirmCasBox = self._writer_cashbox_statement_confirm(confirmCasBox,values)
- return True
- '''
- get cashbox.statement.confirm
- '''
- def _get_cashbox_statement_confirm(self, statement):
- return self.env['cashbox.statement.confirm'].search([
- ('statement_id.type_statement.id', '=', statement.type_statement.id),
- ('user_statement', '=', statement.user_id.id),
- ('journal_id', '=', statement.journal_id.id),
- ('state_avaliable', '=', True),
- # ('amount_next_open', '>', 0.0),
- ('statement_id.id', '!=', statement.id)])
- '''
- writer casbox statement confirm
- '''
- def _writer_cashbox_statement_confirm(self, casbox, values):
- return casbox.write(values)
- '''
- method Open CashBox
- '''
- @api.multi
- def button_open(self):
- self.account_bank_statement_open(self.id)
- return super(AccountBankStatementUtility, self).button_open()
- '''
- _ _ _ _ _ ____ _ _ _
- | | | |_ __ | (_)_ __ | | __ / ___|| |_ __ _| |_ ___ _ __ ___ ___ _ __ | |_
- | | | | '_ \| | | '_ \| |/ / \___ \| __/ _` | __/ _ \ '_ ` _ \ / _ \ '_ \| __|
- | |_| | | | | | | | | | < ___) | || (_| | || __/ | | | | | __/ | | | |_
- \___/|_| |_|_|_|_| |_|_|\_\ |____/ \__\__,_|\__\___|_| |_| |_|\___|_| |_|\__|
- '''
- '''
- Get Statement
- '''
- @api.model
- def eiru_get_bank_statement_unlink(self, id):
- return [{
- 'id': statement.id,
- 'name': statement.name,
- 'state': statement.state,
- 'currencystatement': {
- 'id': statement.currency.id,
- 'symbol': statement.currency.symbol,
- 'rate': statement.currency.rate,
- 'thousandsSeparator': statement.currency.thousands_separator,
- 'decimalSeparator': statement.currency.decimal_separator,
- 'decimalPlaces': statement.currency.decimal_places,
- 'position': statement.currency.position,
- },
- 'lineStatement': [{
- 'id': line.id,
- 'name': line.name,
- 'ref': line.ref,
- 'amount': line.amount,
- 'date': line.date,
- 'casBoxTransfer': [{
- 'id': transfer.id,
- 'name': transfer.name,
- 'amount': transfer.amount,
- 'ref': transfer.ref,
- 'date': transfer.date,
- 'inputStatement': transfer.input_statement.id,
- 'outputStatement': transfer.output_statement.id,
- 'inputStatementState': transfer.input_statement.state,
- 'outputStatementState': transfer.output_statement.state
- }for transfer in self.env['cash.box.transfer'].search(['|',('input_line.id', '=', line.id), ('output_line.id', '=', line.id)])],
- 'casBoxIn': [{
- 'id': boxIn.id,
- 'name': boxIn.name,
- 'amount': boxIn.amount,
- 'ref': boxIn.ref,
- 'date': boxIn.date,
- 'active': boxIn.active
- }for boxIn in self.env['cash.box.in'].search([('line_id.id', '=', line.id)])],
- 'casBoxOut': [{
- 'id': boxOut.id,
- 'name': boxOut.name,
- 'amount': boxOut.amount,
- 'ref': boxOut.ref,
- 'date': boxOut.date,
- 'active': boxOut.active
- }for boxOut in self.env['cash.box.out'].search([('line_id.id', '=', line.id)])]
- }for line in statement.line_ids]
- }for statement in self.env['account.bank.statement'].browse(id)]
- '''
- Unlink Line Statement
- '''
- def _eiru_unlink_statement_line(self, line):
- '''
- Eliminar las lineas de la caja.
- <-> Actualizar la linea.
- <-> Cancelar la linea.
- <-> Eliminar la linea.
- <-> Retur True
- '''
- ### Update Line
- writeLine = self._write_statement_line_transfer(line)
- ### Cancelar Line
- lineCancel = line.cancel()
- ### Unlink Line
- lineUnlink = line.unlink()
- return True
- '''
- Update CashBox
- '''
- def _eiru_write_cashbox(self, cashbox, values):
- return cashbox.write(values)
- '''
- Unlink Statement
- '''
- @api.model
- def eiru_unlink_statement(self, id):
- statement = self._get_statement_transfer(id)
- if (not statement):
- return {
- 'state': False,
- 'message': 'Error en obtener el registro de caja.'
- }
- ## User
- user = self.env.user
- ## date
- date_server = self.get_server_datetime()
- ### FIlter line ids
- statementLines= map(lambda x: x.id, statement.line_ids)
- # Get casbox Transfer
- cashBoxTransfer = self.env['cash.box.transfer'].search(['|',('input_statement.id', '=', statement.id),('output_statement.id', '=', statement.id)])
- # Get cashBox Input
- cashBoxIn = self.env['cash.box.in'].search([('statement_id.id', '=', statement.id)])
- # Get cashBox Output
- cashBoxOut = self.env['cash.box.out'].search([('statement_id.id', '=', statement.id)])
- # confirm
- cashBoxConfirm = self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statement.id)])
- cashBoxConfirmOpen = self.env['cashbox.statement.confirm'].search([('statement_open.id', '=', statement.id)])
- ### Transfer
- stateTransfer = 'open'
- ref = ''
- for transfer in cashBoxTransfer:
- if (transfer.input_statement):
- if (transfer.input_statement.state == 'confirm'):
- stateTransfer = transfer.input_statement.state
- ref += str(' / ')+ transfer.output_statement.name if (ref) else transfer.output_statement.name
- if (transfer.output_statement):
- if (transfer.output_statement.state == 'confirm'):
- stateTransfer = transfer.output_statement.state
- ref += str(' / ')+ transfer.output_statement.name if (ref) else transfer.output_statement.name
- if (stateTransfer == 'confirm'):
- return {
- 'state': False,
- 'message': 'Existe caja relacionada que ya están cerrada Ref('+str(ref)+')'
- }
- message_deleted = 'La caja '+str(statement.name)+', Fue eliminada por '+str(user.name)+' en '+str(date_server)
- messageDeletedCashBoxConfirm = {
- 'active': False,
- 'state_avaliable': False,
- 'message_deleted': message_deleted
- }
- messageDeletedCashBoxConfirmOpen = {
- 'active': True,
- 'state_avaliable': True,
- 'message_deleted': message_deleted
- }
- messageDeletedCashBox = {
- 'active': False,
- 'message_deleted': message_deleted
- }
- for transfer in cashBoxTransfer:
- lineStatement = transfer.input_line.id in statementLines and transfer.output_line.id or transfer.input_line.id
- bankLine = self.env['account.bank.statement.line'].browse(lineStatement)
- if (not bankLine):
- return {
- 'state': False,
- 'message': 'Error, No fue posible localizar una de las lineas de la transferencia.'
- }
- ### Verificar el estado de la caja
- if (bankLine.statement_id.state == 'confirm'):
- return {
- 'state': False,
- 'message': 'Error, Una de las caja ya esta cerrada.'
- }
- ### Unlink Line Statement
- lineUnlink = self._eiru_unlink_statement_line(bankLine)
- accountCasboxTransfer = self.env['cash.box.transfer'].browse(transfer.id)
- if (not accountCasboxTransfer):
- return {
- 'state': False,
- 'message': 'Error, No fue posible localizar la transferencia.'
- }
- ### Update CashBox transfer
- boxTransfer = self._eiru_write_cashbox(accountCasboxTransfer,messageDeletedCashBox)
- if (cashBoxIn):
- boxIn = self._eiru_write_cashbox(cashBoxIn,messageDeletedCashBox)
- if (cashBoxOut):
- boxOut = self._eiru_write_cashbox(cashBoxOut,messageDeletedCashBox)
- if (cashBoxConfirm):
- confirm = self._eiru_write_cashbox(cashBoxConfirm,messageDeletedCashBoxConfirm)
- if (cashBoxConfirmOpen):
- confirmOpen = self._eiru_write_cashbox(cashBoxConfirmOpen,messageDeletedCashBoxConfirmOpen)
- ### Cancel statement
- cancelStatement = self.eiru_button_cancel(statement)
- ### Eliminar las lineas
- for line in statement.line_ids:
- writeLine = self._write_statement_line_transfer(line)
- lineUnlink = line.unlink()
- ## Unlink Statement
- unlinkStatement = statement.unlink()
- return {
- 'state': True,
- 'message': 'Operacion exitosa'
- }
|