123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, tools, api
- import openerp.addons.decimal_precision as dp
- class cashbox_statement_confirm(models.Model):
- _name = "cashbox.statement.confirm"
- # _inherit = "cashbox.statement.confirm"
- name = fields.Char('name', required=True)
- ref = fields.Char('Ref')
- date = fields.Date()
- active = fields.Boolean('Active', default=True)
- message_confirm = fields.Text('Message Confirm')
- message_deleted = fields.Text('Message Deleted')
- ### Statement confirm - open
- statement_id = fields.Many2one('account.bank.statement', 'Bank Statement Confirm')
- statement_open = fields.Many2one('account.bank.statement', 'Bank Statement Open')
- ## User statement - User Confirm
- user_statement = fields.Many2one('res.users', 'Res user')
- user_confirm = fields.Many2one('res.users', 'Res user')
- ## Journal
- journal_id = fields.Many2one('account.journal', 'Journal')
- ## Line
- line_difference = fields.Many2one('account.bank.statement.line', 'Bank statement line difference')
- line_next_open = fields.Many2one('account.bank.statement.line', 'Bank statement line next open statement')
- line_open = fields.Many2one('account.bank.statement.line', 'Bank statement line open')
- ### Amount
- amount_statement = fields.Float('Amount Statement', digits_compute=dp.get_precision('Account'), required=True)
- amount_real = fields.Float('Amount Real', digits_compute=dp.get_precision('Account'), required=True)
- amount_difference = fields.Float('Amount Difference', digits_compute=dp.get_precision('Account'), required=True)
- amount_next_open = fields.Float('Amount Next open statement', digits_compute=dp.get_precision('Account'), required=True)
- ## estado del regsitro
- state_avaliable = fields.Boolean('Avaliable', default=True, help="True : disponible, False : Utilizado")
- # casbox_transfer_id =fields.Many2one('cash.box.transfer', 'cashBox transfer')
- cashbox_transfer_ids =fields.One2many('cash.box.transfer', 'cashbox_confirm_id', string="transfer id")
- '''
- @fields statement_id = Id de la caja que se esta cerrando.
- @fields user_statement = Id del propietario de la caja.
- @fields journal_id = Id del diario de la caja.
- @fields line_difference = Id de la linea de la caja donde se registro la diferencia del cierre.
- @fields line_next_open = Id de la linea donde se registro el monto de próxima apertura de caja.
- @fields amount_statement = Monto en la caja del sistema.
- @fields amount_real = Monto real del cierre de la caja.
- @fields amount_difference = Monto de la diferencia del cierre.
- @fields amount_next_open = Monto de la próxima apertura de caja.
- @fields user_confirm = Usuario que cerro la caja
- @fields statement_open = Id de la caja que utilize el saldo disponible para proxima apertura
- @fields state_avaliable = 'True': disponible, 'False': Utilizado
- @fields cashbox_transfer_ids= id transferencia
- '''
- '''
- ____ _ _ ____ __ _
- | _ \ _ __(_)_ __ | |_ / ___|___ _ __ / _(_)_ __ _ __ ___
- | |_) | '__| | '_ \| __| | | / _ \| '_ \| |_| | '__| '_ ` _ \
- | __/| | | | | | | |_ | |__| (_) | | | | _| | | | | | | | |
- |_| |_| |_|_| |_|\__| \____\___/|_| |_|_| |_|_| |_| |_| |_| v 1.0
- '''
- @api.model
- def get_cashbox_statement_confirm(self, statementId):
- return[{
- 'id': casBox.id,
- 'name': casBox.name,
- 'statement': {
- 'id': casBox.statement_id.id,
- 'name': casBox.statement_id.name,
- 'dateOpen': casBox.statement_id.date,
- 'dateConfirm': casBox.statement_id.closing_date,
- 'typeStatementID': casBox.statement_id.type_statement.id,
- 'typeStatementName': casBox.statement_id.type_statement.name,
- 'userId': casBox.statement_id.user_id.id,
- 'userName': casBox.statement_id.user_id.name,
- 'currencystatement': {
- 'id': casBox.statement_id.currency.id,
- 'name': casBox.statement_id.currency.name,
- 'symbol': casBox.statement_id.currency.symbol,
- 'rate': casBox.statement_id.currency.rate,
- 'thousandsSeparator': casBox.statement_id.currency.thousands_separator,
- 'decimalSeparator': casBox.statement_id.currency.decimal_separator,
- 'decimalPlaces': casBox.statement_id.currency.decimal_places,
- 'position': casBox.statement_id.currency.position,
- },
- },
- 'userStatementName': casBox.user_statement.name,
- 'userStatementLogin': casBox.user_statement.login,
- 'userConfirmName': casBox.user_confirm.name,
- 'userConfirmLogin': casBox.user_confirm.login,
- 'amountStatement': casBox.amount_statement,
- 'amountReal': casBox.amount_real,
- 'amountDifference': casBox.amount_difference,
- 'amountNextOpen': casBox.amount_next_open,
- 'transferCasBox': [{
- 'id': confirm.id,
- 'name': confirm.name,
- 'amount': confirm.amount
- } for confirm in self.env['cash.box.transfer'].search([('cashbox_confirm_id.id', '=', casBox.id)])],
- } for casBox in self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statementId), ('active', '=', True)])]
- '''
- Transfer
- '''
- class cash_box_transfer(models.Model):
- _inherit = "cash.box.transfer"
- cashbox_confirm_id = fields.Many2one('cashbox.statement.confirm', string='cashBox Confirm', ondelete='cascade', index=True)
- '''
- Output
- '''
- class cash_box_output(models.Model):
- _inherit = "cash.box.out"
- cashbox_confirm_id = fields.Many2one('cashbox.statement.confirm', string='cashBox Confirm', ondelete='cascade', index=True)
- '''
- cashbox.statement.confirm
- '''
- class cashboxStatementConfirm(models.Model):
- _inherit = "cashbox.statement.confirm"
- cashbox_output_ids =fields.One2many('cash.box.out', 'cashbox_confirm_id', string="transfer id")
- ''' ____ _ _ ____ __ _
- / ___|__ _ ___| |__ | |__ _____ __ / ___|___ _ __ / _(_)_ __ _ __ ___
- | | / _` / __| '_ \| '_ \ / _ \ \/ / | | / _ \| '_ \| |_| | '__| '_ ` _ \
- | |__| (_| \__ \ | | | |_) | (_) > < | |__| (_) | | | | _| | | | | | | | |
- \____\__,_|___/_| |_|_.__/ \___/_/\_\ \____\___/|_| |_|_| |_|_| |_| |_| |_| v 2.0
- '''
- class AccountBankStatementConfirm(models.Model):
- _inherit = 'account.bank.statement'
- '''
- GET CASHBOX GENERAL.
- '''
- @api.model
- def get_account_bank_statement_general(self, id):
- bankStatement = self._get_statement_transfer(id)
- return [{
- 'id': statement.id,
- 'journalId': statement.journal_id.id,
- 'date': statement.date,
- 'typeStatementId': statement.type_statement.id,
- 'typeStatementName': statement.type_statement.name,
- 'userId': statement.user_id.id,
- 'userName': statement.user_id.name,
- 'name': statement.name,
- 'state': statement.state,
- 'statementname': statement.name+" / "+statement.user_id.name
- } for statement in self.env['account.bank.statement'].search([('state', '=', 'open'), ('id', '!=', bankStatement.id), ('type_statement.code', '=', 'GENERAL'), ('journal_id.id', '=', bankStatement.journal_id.id)])]
- '''
- Confirm Statement
- '''
- @api.model
- def account_bank_statement_confirm(self, values):
- ## Date Server
- date_server = self.get_server_datetime()
- ## User
- user = self.env.user
- ## Statement
- bankStatement = self._get_statement_transfer(values['statementId'])
- if (not bankStatement):
- return {
- 'state': False,
- 'message': "Error en obtener la caja base."
- }
- casboxConfirm = self._get_casbox_confirm(bankStatement.id)
- amountStatement = 0.0
- for line in bankStatement.line_ids:
- amountStatement += line.amount
- if (bankStatement.balance_start > 0):
- amountStatement += bankStatement.balance_start
- amountReal = 0 if (values['amountReal'] < 0) else values['amountReal']
- ## Diference
- lineBalance = []
- if (amountStatement != amountReal):
- name = "Ajuste de cierre de caja "
- lineBalance = self._create_statement_line_confirm(bankStatement, name, (amountReal - amountStatement),values['refBalance'])
- ## TRANSFERENCIA
- cash_box_transfer = []
- if (values['transfer']):
- statementTransfer = self._get_statement_transfer(values['statementTransfer'])
- if (not statementTransfer):
- return {
- 'state': False,
- 'message': "Error al obtener la caja general."
- }
- name = "TRANSFERENCIA/"+str(statementTransfer.name)
- lineTransfer = self._create_statement_line_transfer(bankStatement, name, (-values['amountTransfer']), values['refTransfer'])
- if (not lineTransfer):
- return {
- 'state': False,
- 'message': "Error al registrar la transferencia."
- }
- name = "TRANSFERENCIA/"+str(bankStatement.name)
- lineGeneralTransfer = self._create_statement_line_transfer(statementTransfer, name, (values['amountTransfer']), values['refTransfer'])
- if (not lineGeneralTransfer):
- return {
- 'state': False,
- 'message': "Error al registrar la transferencia."
- }
- cash_box_transfer = self._create_cash_box_transfer(values['refTransfer'], abs(values['amountTransfer']), lineGeneralTransfer, lineTransfer)
- if (not cash_box_transfer):
- return {
- 'state': False,
- 'message': "Error al registrar la transferencia."
- }
- amountNextOpen = 0.0
- for line in bankStatement.line_ids:
- amountNextOpen += line.amount
- if (bankStatement.balance_start > 0):
- amountNextOpen += bankStatement.balance_start
- lineNextOpen = []
- if (amountNextOpen > 0):
- name ="Saldo para próxima apertura de caja."
- ref = "Cierre"
- lineNextOpen = self._create_statement_line_transfer(bankStatement, name, -amountNextOpen, ref)
- ## chasbox Confirm
- cashboxConfirm = {
- 'name': "CIERRE DE CAJA /"+str(bankStatement.name),
- 'date': date_server,
- 'ref': values['refBalance'],
- 'statement_id': bankStatement.id,
- 'user_statement': bankStatement.user_id.id,
- 'user_confirm': user.id,
- 'journal_id' : bankStatement.journal_id.id,
- 'amount_statement': amountStatement,
- 'amount_real': values['amountReal'],
- 'line_difference': lineBalance.id if (lineBalance) else '',
- 'amount_difference': lineBalance.amount if (lineBalance) else 0.0,
- 'line_next_open': lineNextOpen.id if(lineNextOpen) else '',
- 'amount_next_open': abs(lineNextOpen.amount) if(lineNextOpen) else 0.0,
- 'state_avaliable': True if(lineNextOpen and abs(lineNextOpen.amount) > 0) else False,
- }
- statementConfirm = self._create_cashbox_statement_confirm(cashboxConfirm, bankStatement)
- if (not statementConfirm):
- return {
- 'state': False,
- 'message': "Error en el cierre de caja ."
- }
- if (cash_box_transfer):
- cash_box_transfer.write({'cashbox_confirm_id': statementConfirm.id })
- confirm = bankStatement.button_confirm_cash()
- if (not confirm):
- return {
- 'state': False,
- 'message': "Error en el cierre de caja ."
- }
- return {
- 'state': True,
- 'message': "Operación realizada con suceso."
- }
- '''
- Get Cashbox statement Confirm
- '''
- def _get_casbox_confirm(self,statementId):
- return self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statementId)])
- '''
- Create Line statement.
- '''
- def _create_statement_line_confirm(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
- }
- return self.env['account.bank.statement.line'].create(statementLine)
- '''
- Create cashbox Confirm
- '''
- def _create_cashbox_statement_confirm(self,values, statement):
- casbox = self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statement.id)])
- if (not casbox):
- confirm = self.env['cashbox.statement.confirm'].create(values)
- else:
- confirm = casbox.write(values)
- if (confirm):
- confirm = self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statement.id)])
- return confirm
|