cashbox_statement_confirm.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, tools, api
  3. import openerp.addons.decimal_precision as dp
  4. class cashbox_statement_confirm(models.Model):
  5. _name = "cashbox.statement.confirm"
  6. # _inherit = "cashbox.statement.confirm"
  7. name = fields.Char('name', required=True)
  8. ref = fields.Char('Ref')
  9. date = fields.Date()
  10. active = fields.Boolean('Active', default=True)
  11. message_confirm = fields.Text('Message Confirm')
  12. message_deleted = fields.Text('Message Deleted')
  13. ### Statement confirm - open
  14. statement_id = fields.Many2one('account.bank.statement', 'Bank Statement Confirm')
  15. statement_open = fields.Many2one('account.bank.statement', 'Bank Statement Open')
  16. ## User statement - User Confirm
  17. user_statement = fields.Many2one('res.users', 'Res user')
  18. user_confirm = fields.Many2one('res.users', 'Res user')
  19. ## Journal
  20. journal_id = fields.Many2one('account.journal', 'Journal')
  21. ## Line
  22. line_difference = fields.Many2one('account.bank.statement.line', 'Bank statement line difference')
  23. line_next_open = fields.Many2one('account.bank.statement.line', 'Bank statement line next open statement')
  24. line_open = fields.Many2one('account.bank.statement.line', 'Bank statement line open')
  25. ### Amount
  26. amount_statement = fields.Float('Amount Statement', digits_compute=dp.get_precision('Account'), required=True)
  27. amount_real = fields.Float('Amount Real', digits_compute=dp.get_precision('Account'), required=True)
  28. amount_difference = fields.Float('Amount Difference', digits_compute=dp.get_precision('Account'), required=True)
  29. amount_next_open = fields.Float('Amount Next open statement', digits_compute=dp.get_precision('Account'), required=True)
  30. ## estado del regsitro
  31. state_avaliable = fields.Boolean('Avaliable', default=True, help="True : disponible, False : Utilizado")
  32. # casbox_transfer_id =fields.Many2one('cash.box.transfer', 'cashBox transfer')
  33. cashbox_transfer_ids =fields.One2many('cash.box.transfer', 'cashbox_confirm_id', string="transfer id")
  34. '''
  35. @fields statement_id = Id de la caja que se esta cerrando.
  36. @fields user_statement = Id del propietario de la caja.
  37. @fields journal_id = Id del diario de la caja.
  38. @fields line_difference = Id de la linea de la caja donde se registro la diferencia del cierre.
  39. @fields line_next_open = Id de la linea donde se registro el monto de próxima apertura de caja.
  40. @fields amount_statement = Monto en la caja del sistema.
  41. @fields amount_real = Monto real del cierre de la caja.
  42. @fields amount_difference = Monto de la diferencia del cierre.
  43. @fields amount_next_open = Monto de la próxima apertura de caja.
  44. @fields user_confirm = Usuario que cerro la caja
  45. @fields statement_open = Id de la caja que utilize el saldo disponible para proxima apertura
  46. @fields state_avaliable = 'True': disponible, 'False': Utilizado
  47. @fields cashbox_transfer_ids= id transferencia
  48. '''
  49. '''
  50. ____ _ _ ____ __ _
  51. | _ \ _ __(_)_ __ | |_ / ___|___ _ __ / _(_)_ __ _ __ ___
  52. | |_) | '__| | '_ \| __| | | / _ \| '_ \| |_| | '__| '_ ` _ \
  53. | __/| | | | | | | |_ | |__| (_) | | | | _| | | | | | | | |
  54. |_| |_| |_|_| |_|\__| \____\___/|_| |_|_| |_|_| |_| |_| |_| v 1.0
  55. '''
  56. @api.model
  57. def get_cashbox_statement_confirm(self, statementId):
  58. return[{
  59. 'id': casBox.id,
  60. 'name': casBox.name,
  61. 'statement': {
  62. 'id': casBox.statement_id.id,
  63. 'name': casBox.statement_id.name,
  64. 'dateOpen': casBox.statement_id.date,
  65. 'dateConfirm': casBox.statement_id.closing_date,
  66. 'typeStatementID': casBox.statement_id.type_statement.id,
  67. 'typeStatementName': casBox.statement_id.type_statement.name,
  68. 'userId': casBox.statement_id.user_id.id,
  69. 'userName': casBox.statement_id.user_id.name,
  70. 'currencystatement': {
  71. 'id': casBox.statement_id.currency.id,
  72. 'name': casBox.statement_id.currency.name,
  73. 'symbol': casBox.statement_id.currency.symbol,
  74. 'rate': casBox.statement_id.currency.rate,
  75. 'thousandsSeparator': casBox.statement_id.currency.thousands_separator,
  76. 'decimalSeparator': casBox.statement_id.currency.decimal_separator,
  77. 'decimalPlaces': casBox.statement_id.currency.decimal_places,
  78. 'position': casBox.statement_id.currency.position,
  79. },
  80. },
  81. 'userStatementName': casBox.user_statement.name,
  82. 'userStatementLogin': casBox.user_statement.login,
  83. 'userConfirmName': casBox.user_confirm.name,
  84. 'userConfirmLogin': casBox.user_confirm.login,
  85. 'amountStatement': casBox.amount_statement,
  86. 'amountReal': casBox.amount_real,
  87. 'amountDifference': casBox.amount_difference,
  88. 'amountNextOpen': casBox.amount_next_open,
  89. 'transferCasBox': [{
  90. 'id': confirm.id,
  91. 'name': confirm.name,
  92. 'amount': confirm.amount
  93. } for confirm in self.env['cash.box.transfer'].search([('cashbox_confirm_id.id', '=', casBox.id)])],
  94. } for casBox in self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statementId), ('active', '=', True)])]
  95. '''
  96. Transfer
  97. '''
  98. class cash_box_transfer(models.Model):
  99. _inherit = "cash.box.transfer"
  100. cashbox_confirm_id = fields.Many2one('cashbox.statement.confirm', string='cashBox Confirm', ondelete='cascade', index=True)
  101. '''
  102. Output
  103. '''
  104. class cash_box_output(models.Model):
  105. _inherit = "cash.box.out"
  106. cashbox_confirm_id = fields.Many2one('cashbox.statement.confirm', string='cashBox Confirm', ondelete='cascade', index=True)
  107. '''
  108. cashbox.statement.confirm
  109. '''
  110. class cashboxStatementConfirm(models.Model):
  111. _inherit = "cashbox.statement.confirm"
  112. cashbox_output_ids =fields.One2many('cash.box.out', 'cashbox_confirm_id', string="transfer id")
  113. ''' ____ _ _ ____ __ _
  114. / ___|__ _ ___| |__ | |__ _____ __ / ___|___ _ __ / _(_)_ __ _ __ ___
  115. | | / _` / __| '_ \| '_ \ / _ \ \/ / | | / _ \| '_ \| |_| | '__| '_ ` _ \
  116. | |__| (_| \__ \ | | | |_) | (_) > < | |__| (_) | | | | _| | | | | | | | |
  117. \____\__,_|___/_| |_|_.__/ \___/_/\_\ \____\___/|_| |_|_| |_|_| |_| |_| |_| v 2.0
  118. '''
  119. class AccountBankStatementConfirm(models.Model):
  120. _inherit = 'account.bank.statement'
  121. '''
  122. GET CASHBOX GENERAL.
  123. '''
  124. @api.model
  125. def get_account_bank_statement_general(self, id):
  126. bankStatement = self._get_statement_transfer(id)
  127. return [{
  128. 'id': statement.id,
  129. 'journalId': statement.journal_id.id,
  130. 'date': statement.date,
  131. 'typeStatementId': statement.type_statement.id,
  132. 'typeStatementName': statement.type_statement.name,
  133. 'userId': statement.user_id.id,
  134. 'userName': statement.user_id.name,
  135. 'name': statement.name,
  136. 'state': statement.state,
  137. 'statementname': statement.name+" / "+statement.user_id.name
  138. } 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)])]
  139. '''
  140. Confirm Statement
  141. '''
  142. @api.model
  143. def account_bank_statement_confirm(self, values):
  144. ## Date Server
  145. date_server = self.get_server_datetime()
  146. ## User
  147. user = self.env.user
  148. ## Statement
  149. bankStatement = self._get_statement_transfer(values['statementId'])
  150. if (not bankStatement):
  151. return {
  152. 'state': False,
  153. 'message': "Error en obtener la caja base."
  154. }
  155. casboxConfirm = self._get_casbox_confirm(bankStatement.id)
  156. amountStatement = 0.0
  157. for line in bankStatement.line_ids:
  158. amountStatement += line.amount
  159. if (bankStatement.balance_start > 0):
  160. amountStatement += bankStatement.balance_start
  161. amountReal = 0 if (values['amountReal'] < 0) else values['amountReal']
  162. ## Diference
  163. lineBalance = []
  164. if (amountStatement != amountReal):
  165. name = "Ajuste de cierre de caja "
  166. lineBalance = self._create_statement_line_confirm(bankStatement, name, (amountReal - amountStatement),values['refBalance'])
  167. ## TRANSFERENCIA
  168. cash_box_transfer = []
  169. if (values['transfer']):
  170. statementTransfer = self._get_statement_transfer(values['statementTransfer'])
  171. if (not statementTransfer):
  172. return {
  173. 'state': False,
  174. 'message': "Error al obtener la caja general."
  175. }
  176. name = "TRANSFERENCIA/"+str(statementTransfer.name)
  177. lineTransfer = self._create_statement_line_transfer(bankStatement, name, (-values['amountTransfer']), values['refTransfer'])
  178. if (not lineTransfer):
  179. return {
  180. 'state': False,
  181. 'message': "Error al registrar la transferencia."
  182. }
  183. name = "TRANSFERENCIA/"+str(bankStatement.name)
  184. lineGeneralTransfer = self._create_statement_line_transfer(statementTransfer, name, (values['amountTransfer']), values['refTransfer'])
  185. if (not lineGeneralTransfer):
  186. return {
  187. 'state': False,
  188. 'message': "Error al registrar la transferencia."
  189. }
  190. cash_box_transfer = self._create_cash_box_transfer(values['refTransfer'], abs(values['amountTransfer']), lineGeneralTransfer, lineTransfer)
  191. if (not cash_box_transfer):
  192. return {
  193. 'state': False,
  194. 'message': "Error al registrar la transferencia."
  195. }
  196. amountNextOpen = 0.0
  197. for line in bankStatement.line_ids:
  198. amountNextOpen += line.amount
  199. if (bankStatement.balance_start > 0):
  200. amountNextOpen += bankStatement.balance_start
  201. lineNextOpen = []
  202. if (amountNextOpen > 0):
  203. name ="Saldo para próxima apertura de caja."
  204. ref = "Cierre"
  205. lineNextOpen = self._create_statement_line_transfer(bankStatement, name, -amountNextOpen, ref)
  206. ## chasbox Confirm
  207. cashboxConfirm = {
  208. 'name': "CIERRE DE CAJA /"+str(bankStatement.name),
  209. 'date': date_server,
  210. 'ref': values['refBalance'],
  211. 'statement_id': bankStatement.id,
  212. 'user_statement': bankStatement.user_id.id,
  213. 'user_confirm': user.id,
  214. 'journal_id' : bankStatement.journal_id.id,
  215. 'amount_statement': amountStatement,
  216. 'amount_real': values['amountReal'],
  217. 'line_difference': lineBalance.id if (lineBalance) else '',
  218. 'amount_difference': lineBalance.amount if (lineBalance) else 0.0,
  219. 'line_next_open': lineNextOpen.id if(lineNextOpen) else '',
  220. 'amount_next_open': abs(lineNextOpen.amount) if(lineNextOpen) else 0.0,
  221. 'state_avaliable': True if(lineNextOpen and abs(lineNextOpen.amount) > 0) else False,
  222. }
  223. statementConfirm = self._create_cashbox_statement_confirm(cashboxConfirm, bankStatement)
  224. if (not statementConfirm):
  225. return {
  226. 'state': False,
  227. 'message': "Error en el cierre de caja ."
  228. }
  229. if (cash_box_transfer):
  230. cash_box_transfer.write({'cashbox_confirm_id': statementConfirm.id })
  231. confirm = bankStatement.button_confirm_cash()
  232. if (not confirm):
  233. return {
  234. 'state': False,
  235. 'message': "Error en el cierre de caja ."
  236. }
  237. return {
  238. 'state': True,
  239. 'message': "Operación realizada con suceso."
  240. }
  241. '''
  242. Get Cashbox statement Confirm
  243. '''
  244. def _get_casbox_confirm(self,statementId):
  245. return self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statementId)])
  246. '''
  247. Create Line statement.
  248. '''
  249. def _create_statement_line_confirm(self, statement, name, amount, ref):
  250. statementLine = {
  251. 'statement_id': statement.id,
  252. 'name': name,
  253. 'amount': amount,
  254. 'ref': ref,
  255. 'account_id': statement.journal_id.internal_account_id.id,
  256. 'journal_id': statement.journal_id.id,
  257. 'is_deleted': True
  258. }
  259. return self.env['account.bank.statement.line'].create(statementLine)
  260. '''
  261. Create cashbox Confirm
  262. '''
  263. def _create_cashbox_statement_confirm(self,values, statement):
  264. casbox = self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statement.id)])
  265. if (not casbox):
  266. confirm = self.env['cashbox.statement.confirm'].create(values)
  267. else:
  268. confirm = casbox.write(values)
  269. if (confirm):
  270. confirm = self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statement.id)])
  271. return confirm