account_bank_statement.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # -*- coding: utf-8 -*-
  2. from openerp.http import request
  3. '''
  4. ██████ █████ ███ ██ ██ ██ ███████ ████████ █████ ████████ ███████ ███ ███ ███████ ███ ██ ████████
  5. ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██
  6. ██████ ███████ ██ ██ ██ █████ ███████ ██ ███████ ██ █████ ██ ████ ██ █████ ██ ██ ██ ██
  7. ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
  8. ██████ ██ ██ ██ ████ ██ ██ ██ ███████ ██ ██ ██ ██ ███████ ██ ██ ███████ ██ ████ ██
  9. '''
  10. _MODEL = 'account.bank.statement'
  11. '''
  12. ██████ ███████ ████████
  13. ██ ██ ██
  14. ██ ███ █████ ██
  15. ██ ██ ██ ██
  16. ██████ ███████ ██
  17. '''
  18. def search_account_bank_statement(statementId):
  19. casbox= []
  20. statement = request.env['account.bank.statement'].browse(statementId)
  21. if (statement):
  22. casbox = {
  23. 'id': statement.id,
  24. 'name': statement.name,
  25. 'accountId': statement.journal_id.internal_account_id.id,
  26. 'journalId': statement.journal_id.id,
  27. 'balanceEnd': statement.balance_end
  28. }
  29. return casbox
  30. '''
  31. ██████ ██████ ███████ █████ ████████ ███████
  32. ██ ██ ██ ██ ██ ██ ██ ██
  33. ██ ██████ █████ ███████ ██ █████
  34. ██ ██ ██ ██ ██ ██ ██ ██
  35. ██████ ██ ██ ███████ ██ ██ ██ ███████ ██ Account Bank Statement
  36. '''
  37. def create_account_bank_statement(data):
  38. from account_bank_statement_config import get_bank_statement_config
  39. config = get_bank_statement_config()
  40. if (not config):
  41. return {
  42. 'state': False,
  43. 'message': 'No existe configuración de caja'
  44. }
  45. domain = [('journal_id', '=', data['journal_id']),('type_statement', '=', data['type_statement']),('user_id', '=', data['user_id']),('state', '=', 'open')]
  46. statementVerify = request.env[_MODEL].search(domain)
  47. if ((not config.statement_open_config) and (statementVerify)):
  48. return {
  49. 'state': False,
  50. 'message': 'Ya existe una caja abierta con los mismos parámetros'
  51. }
  52. ''' Create CashBox '''
  53. statement = request.env[_MODEL].sudo().create(data)
  54. if(not statement):
  55. return {
  56. 'state': False,
  57. 'message': 'No fue posible crear la caja'
  58. }
  59. ''' Open cashBox '''
  60. openStatement = statement.sudo().button_open()
  61. if (not openStatement):
  62. return {
  63. 'state': False,
  64. 'message': 'No fue posible abrir la caja '
  65. }
  66. return {
  67. 'state': openStatement,
  68. 'message': 'Caja creada con éxito',
  69. 'data' : {
  70. 'id': statement.id,
  71. 'name': statement.name,
  72. 'date': statement.date,
  73. 'state': statement.state,
  74. 'balanceEnd': statement.balance_end,
  75. 'user': {
  76. 'id': statement.user_id.id,
  77. 'name': statement.user_id.name,
  78. 'displayName': statement.user_id.display_name
  79. },
  80. 'userSession': request.env.user.id,
  81. 'journal': {
  82. 'id': statement.journal_id.id,
  83. 'name': statement.journal_id.name,
  84. 'displayName': statement.journal_id.display_name,
  85. 'code': statement.journal_id.code,
  86. 'cashControl': statement.journal_id.cash_control,
  87. 'type': statement.journal_id.type,
  88. 'currency': {
  89. 'id': statement.journal_id.currency.id,
  90. 'name': statement.journal_id.currency.name,
  91. 'displayName': statement.journal_id.currency.display_name
  92. }
  93. },
  94. 'line': [{
  95. 'id': line.id,
  96. 'date': line.date,
  97. 'name': line.name,
  98. 'ref': line.ref,
  99. 'amount': line.amount,
  100. 'patner':{
  101. 'id': line.partner_id.id,
  102. 'name': line.partner_id.name,
  103. 'displayName': line.partner_id.display_name
  104. },
  105. } for line in statement.line_ids],
  106. 'typeStatement': {
  107. 'id': statement.type_statement.id,
  108. 'name': statement.type_statement.name,
  109. 'code': statement.type_statement.code
  110. },
  111. 'currency':{
  112. 'id': statement.currency.id,
  113. 'name': statement.currency.display_name,
  114. 'base': statement.currency.base,
  115. 'symbol': statement.currency.symbol,
  116. 'position': statement.currency.position,
  117. 'rateSilent': statement.currency.rate_silent,
  118. 'decimalSeparator': statement.currency.decimal_separator,
  119. 'decimalPlaces': statement.currency.decimal_places,
  120. 'thousandsSeparator': statement.currency.thousands_separator
  121. }
  122. }
  123. }
  124. '''
  125. ██████ ██ ██████ ███████ ██ ███ ██ ██████
  126. ██ ██ ██ ██ ██ ██ ████ ██ ██
  127. ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ███
  128. ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
  129. ██████ ███████ ██████ ███████ ██ ██ ████ ██████ bank Statement
  130. '''
  131. def closing_statement(data):
  132. from account_bank_statement_line import create_statement_line
  133. from cashbox_confirm import get_cashbox_statement_confirm, create_cashbox_statement_confirm, write_cashbox_statement_confirm
  134. from server_datetime import get_date
  135. lineDifference = []
  136. lineclosing = []
  137. statement = request.env[_MODEL].browse(data['statementId'])
  138. if (not statement):
  139. return {
  140. 'state': False,
  141. 'message': 'No fue posible localizar la caja.'
  142. }
  143. amountStatement = statement.balance_end or 0.0
  144. ''' Registrar Diferencia entre saldos '''
  145. if (statement.balance_end != data['amount']):
  146. lineDifference = create_statement_line({
  147. 'statement_id': statement.id,
  148. 'name': "Diferencia entre valor teórico de cierre y valor real de cierre.",
  149. 'amount': data['amount'] - statement.balance_end,
  150. 'ref': 'AJUSTE DE CIERRE',
  151. 'account_id': statement.journal_id.internal_account_id.id,
  152. 'journal_id': statement.journal_id.id,
  153. # 'is_deleted': True
  154. })
  155. if (not lineDifference):
  156. return {
  157. 'state': False,
  158. 'message': 'No fue posible registrar el ajuste de cierre.'
  159. }
  160. ''' Resgitro de saldo '''
  161. if (statement.balance_end != 0):
  162. lineclosing = create_statement_line({
  163. 'statement_id': statement.id,
  164. 'name': "Registro de saldo para próxima apertura.",
  165. 'amount': - statement.balance_end if (statement.balance_end > 0) else abs(statement.balance_end),
  166. 'ref': 'CIERRE DE CAJA',
  167. 'account_id': statement.journal_id.internal_account_id.id,
  168. 'journal_id': statement.journal_id.id,
  169. # 'is_deleted': True
  170. })
  171. if (not lineclosing):
  172. return {
  173. 'state': False,
  174. 'message': 'No fue posible registrar el cierre de caja.'
  175. }
  176. amountNexOpen = abs(lineclosing.amount) if (lineclosing.amount < 0 ) else - (lineclosing.amount)
  177. # import web_pdb; web_pdb.set_trace()
  178. ''' Registro de Cierre de caja '''
  179. statementConfirm = get_cashbox_statement_confirm([('statement_id.id', '=', statement.id)])
  180. cashboxConfirm = {
  181. 'name': "CIERRE DE CAJA /"+str(statement.name),
  182. 'date': get_date(),
  183. 'ref': data['description'],
  184. 'statement_id': statement.id,
  185. 'user_statement': statement.user_id.id,
  186. 'user_confirm': request.env.user.id,
  187. 'journal_id' : statement.journal_id.id,
  188. 'amount_statement': amountStatement,
  189. 'amount_real': data['amount'],
  190. 'line_difference': lineDifference.id if (lineDifference) else '',
  191. 'amount_difference': lineDifference.amount if (lineDifference) else 0.0,
  192. 'line_next_open': lineclosing.id if(lineclosing) else '',
  193. 'amount_next_open': amountNexOpen if(lineclosing) else 0.0,
  194. 'state_avaliable': True if(lineclosing and abs(lineclosing.amount) > 0) else False,
  195. }
  196. confirm = create_cashbox_statement_confirm(cashboxConfirm) if (not statementConfirm) else write_cashbox_statement_confirm(statementConfirm.id, cashboxConfirm)
  197. if (not confirm):
  198. return {
  199. 'state': False,
  200. 'message': 'No fue posible crear el cierre de caja'
  201. }
  202. response = statement.button_confirm_cash()
  203. if (not response):
  204. return {
  205. 'state': False,
  206. 'message': 'No fue posible cerrar la caja'
  207. }
  208. return {
  209. 'state': True,
  210. 'message': 'Cierre de caja, realizada con éxito.'
  211. }