account_bank_statement_utility.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, tools, api
  3. from datetime import datetime
  4. from pytz import timezone
  5. DATE_FORMAT = '%Y-%m-%d'
  6. class AccountBankStatementUtility(models.Model):
  7. _inherit = 'account.bank.statement'
  8. '''
  9. get_account_bank_statement_utility
  10. '''
  11. @api.model
  12. def get_account_bank_statement_utility(self, id):
  13. '''
  14. Get Account Bank Statement
  15. :param : id: id account bank statement,
  16. :return : Object Account bank statement + Amount(account Bank statement line)
  17. '''
  18. decimal_precision = self.env['decimal.precision'].precision_get('Account')
  19. bankStatement = self.env['account.bank.statement'].browse(id)
  20. if (not bankStatement):
  21. return False
  22. accountStatement = []
  23. amount = 0.0
  24. for line in bankStatement.line_ids:
  25. amount += line.amount
  26. if (bankStatement.balance_start > 0):
  27. amount += bankStatement.balance_start
  28. accountStatement.append({
  29. 'id': bankStatement.id,
  30. 'name': bankStatement.name,
  31. 'date': bankStatement.date,
  32. 'journalId': bankStatement.journal_id.id,
  33. 'periodId': bankStatement.period_id.id,
  34. 'userId': bankStatement.user_id.id,
  35. 'userName': bankStatement.user_id.name,
  36. 'typeStatement': bankStatement.type_statement.id,
  37. 'typeStatementName': bankStatement.type_statement.name,
  38. 'state': bankStatement.state,
  39. 'amount': round(amount,decimal_precision),
  40. 'currencystatement': {
  41. 'id': bankStatement.currency.id,
  42. 'symbol': bankStatement.currency.symbol,
  43. 'rate': bankStatement.currency.rate,
  44. 'thousandsSeparator': bankStatement.currency.thousands_separator,
  45. 'decimalSeparator': bankStatement.currency.decimal_separator,
  46. 'decimalPlaces': bankStatement.currency.decimal_places,
  47. 'position': bankStatement.currency.position,
  48. },
  49. })
  50. return accountStatement
  51. @api.model
  52. def get_account_journal_utility(self,id):
  53. bankStatement = self.env['account.bank.statement'].browse(id)
  54. if (not bankStatement):
  55. return False
  56. domain = [('active', '=', True), ('type', 'in', ['bank', 'cash']), ('id', 'in', [bankStatement.journal_id.id])];
  57. accountJournal = self.env['account.journal'].search(domain)
  58. journalUtility = []
  59. for journal in accountJournal:
  60. domainStatment = [('id','!=',bankStatement.id),('journal_id','in',[journal.id])]
  61. # domainStatment = [('id','!=',bankStatement.id) ,('journal_id','in',[journal.id]),('date','=',bankStatement.date),('period_id','=',bankStatement.period_id.id)]
  62. if (journal.type == 'cash'):
  63. domainStatment.append(('state','=', 'open'))
  64. if (journal.type == 'bank'):
  65. domainStatment.append(('state','!=','confirm'))
  66. statementJournal = []
  67. statement = self.env['account.bank.statement'].search(domainStatment)
  68. for statementOpen in statement:
  69. statementJournal.append({
  70. 'id': statementOpen.id,
  71. 'journalId': statementOpen.journal_id.id,
  72. 'date': statementOpen.date,
  73. 'typeStatementId': statementOpen.type_statement.id,
  74. 'typeStatementName': statementOpen.type_statement.name,
  75. 'userId': statementOpen.user_id.id,
  76. 'userName': statementOpen.user_id.name,
  77. 'name': statementOpen.name,
  78. 'state': statementOpen.state,
  79. 'statementname': statementOpen.name+" / "+statementOpen.user_id.name
  80. })
  81. journalUtility.append({
  82. 'id': journal.id,
  83. 'name': journal.name,
  84. 'code': journal.code,
  85. 'type': journal.type,
  86. 'currencyId': journal.currency.id,
  87. 'statementJournal': statementJournal
  88. })
  89. return journalUtility
  90. '''
  91. Get User Login
  92. '''
  93. @api.model
  94. def eiru_transfers_get_user(self):
  95. return [{
  96. 'id': user.id,
  97. 'name': user.name
  98. } for user in self.env.user]
  99. @api.model
  100. def eiru_transfers_get_chas_box_transfer(self, id):
  101. return [{
  102. 'id': transfer.id,
  103. 'name': transfer.name,
  104. 'amount': transfer.amount,
  105. 'ref': transfer.ref,
  106. 'date': transfer.date,
  107. 'outputStatement': {
  108. 'id': transfer.output_statement.id,
  109. 'name': transfer.output_statement.name,
  110. 'typeJournal': transfer.output_statement.journal_id.type,
  111. 'state': transfer.output_statement.state,
  112. 'date': transfer.output_statement.date,
  113. 'userId': transfer.output_statement.user_id.id,
  114. 'currency': {
  115. 'symbol': transfer.output_statement.currency.symbol,
  116. 'thousandsSeparator': transfer.output_statement.currency.thousands_separator,
  117. 'decimalSeparator': transfer.output_statement.currency.decimal_separator,
  118. 'decimalPlaces': transfer.output_statement.currency.decimal_places,
  119. }
  120. },
  121. 'inputStatement': {
  122. 'id': transfer.input_statement.id,
  123. 'name': transfer.input_statement.name,
  124. 'state': transfer.input_statement.state,
  125. 'typeJournal': transfer.input_statement.journal_id.type,
  126. 'date': transfer.input_statement.date,
  127. 'userId': transfer.input_statement.user_id.id,
  128. 'currency': {
  129. 'symbol': transfer.input_statement.currency.symbol,
  130. 'thousandsSeparator': transfer.input_statement.currency.thousands_separator,
  131. 'decimalSeparator': transfer.input_statement.currency.decimal_separator,
  132. 'decimalPlaces': transfer.input_statement.currency.decimal_places,
  133. }
  134. },
  135. 'outputLine': {
  136. 'id': transfer.output_line.id,
  137. 'statementID': transfer.output_line.statement_id.id,
  138. },
  139. 'inputLine': {
  140. 'id': transfer.input_line.id,
  141. 'statementID': transfer.input_line.statement_id.id,
  142. }
  143. } for transfer in self.env['cash.box.transfer'].search(['|', ('output_statement.id','=',id), ('input_statement.id','=',id)])]
  144. '''
  145. _____ __
  146. |_ _| __ __ _ _ __ ___ / _| ___ _ __ ___
  147. | || '__/ _` | '_ \/ __| |_ / _ \ '__/ __|
  148. | || | | (_| | | | \__ \ _| __/ | \__ \
  149. |_||_| \__,_|_| |_|___/_| \___|_| |___/
  150. '''
  151. '''
  152. Get Account Bank Statement
  153. '''
  154. def _get_statement_transfer(self,id):
  155. return self.env['account.bank.statement'].browse(id)
  156. '''
  157. Get Account Journal
  158. '''
  159. def _get_journal_transfer(self, id):
  160. return self.env['account.journal'].browse(id)
  161. '''
  162. Create Line statement.
  163. '''
  164. def _create_statement_line_transfer(self, statement, name, amount, ref):
  165. statementLine = {
  166. 'statement_id': statement.id,
  167. 'name': name,
  168. 'amount': amount ,
  169. 'ref': ref,
  170. 'account_id': statement.journal_id.internal_account_id.id,
  171. 'journal_id': statement.journal_id.id,
  172. 'is_deleted': True
  173. }
  174. line = self.env['account.bank.statement.line'].create(statementLine)
  175. return line
  176. '''
  177. Create cash box transfer
  178. '''
  179. def _create_cash_box_transfer(self, ref, amount, lineInput, lineOutput):
  180. cash = {
  181. 'name': "TRANSFERENCIA %s a %s" %((lineOutput.statement_id.name),(lineInput.statement_id.name)),
  182. 'amount': amount,
  183. 'ref': ref,
  184. 'input_line': lineInput.id,
  185. 'output_line': lineOutput.id,
  186. 'input_statement': lineInput.statement_id.id,
  187. 'output_statement': lineOutput.statement_id.id,
  188. 'date': lineOutput.date
  189. }
  190. return self.env['cash.box.transfer'].create(cash)
  191. '''
  192. Create Line statement Transfer
  193. '''
  194. @api.model
  195. def statement_complet_transfers(self, values):
  196. statementOrigin = self._get_statement_transfer(values['statementOriginId'])
  197. if (not statementOrigin):
  198. return False
  199. statementDestiny = self._get_statement_transfer(values['statementDestinyId'])
  200. if (not statementDestiny):
  201. return False
  202. accountJournal = self._get_journal_transfer(values['journalID'])
  203. if (not accountJournal):
  204. return False
  205. # output
  206. name = "TRANSFERENCIA/"+str(statementDestiny.name)
  207. statementOutput = self._create_statement_line_transfer(statementOrigin, name,(-values['amountTransfer']), values['refTransfer'])
  208. if (not statementOutput):
  209. return False
  210. # input
  211. name = "TRANSFERENCIA/"+str(statementOrigin.name)
  212. statementInput = self._create_statement_line_transfer(statementDestiny, name, abs(values['amountTransfer']), values['refTransfer'])
  213. if (not statementInput):
  214. return False
  215. cash_box_transfer = self._create_cash_box_transfer(values['refTransfer'], abs(values['amountTransfer']), statementInput, statementOutput)
  216. if (not cash_box_transfer):
  217. return False
  218. return True
  219. '''
  220. _ _ _ _ _ _____ __
  221. | | | |_ __ | (_)_ __ | | __ |_ _| __ __ _ _ __ ___ / _| ___ _ __
  222. | | | | '_ \| | | '_ \| |/ / | || '__/ _` | '_ \/ __| |_ / _ \ '__|
  223. | |_| | | | | | | | | | < | || | | (_| | | | \__ \ _| __/ |
  224. \___/|_| |_|_|_|_| |_|_|\_\ |_||_| \__,_|_| |_|___/_| \___|_|
  225. '''
  226. '''
  227. Get Cash Box Transfer
  228. '''
  229. def _get_cash_box_transfer(self, id):
  230. return self.env['cash.box.transfer'].browse(id)
  231. '''
  232. Get timezone
  233. '''
  234. def get_timezone(self):
  235. tz_name = self._context.get('tz') or self.env.user.tz
  236. return timezone(tz_name)
  237. '''
  238. Get server date
  239. '''
  240. def get_server_datetime(self):
  241. return datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
  242. '''
  243. Get Statement Line
  244. '''
  245. def _get_statement_Line(self, id):
  246. return self.env['account.bank.statement.line'].browse(id)
  247. '''
  248. writer Line Statement
  249. '''
  250. def _write_statement_line_transfer(self, line):
  251. return line.write({
  252. 'is_deleted': False
  253. })
  254. '''
  255. Unlink Line Statement
  256. '''
  257. def _unlink_statement_line_transfer(self, line):
  258. return line.unlink()
  259. '''
  260. Write cash box transfer
  261. '''
  262. def _write_cash_box_transfer(self, casbox, message, user):
  263. return casbox.write({
  264. 'message_deleted': message,
  265. 'active': False,
  266. 'write_uid': user.id
  267. })
  268. '''
  269. unlink Initial
  270. '''
  271. @api.model
  272. def unlink_transfer(self, values):
  273. ### user
  274. user = self.env.user
  275. ### date server
  276. date_server = self.get_server_datetime()
  277. ### account Statement
  278. statement = self._get_statement_transfer(values['statementId'])
  279. if (not statement):
  280. return {
  281. 'state' : False,
  282. 'message': "No se pudo completar la operación."
  283. }
  284. ### Transferencia
  285. cashBoxTransfer = self._get_cash_box_transfer(values['transferId'])
  286. if (not cashBoxTransfer):
  287. return {
  288. 'state' : False,
  289. 'message': "No se pudo completar la operación."
  290. }
  291. ### Line output
  292. lineOutput = self._get_statement_Line(cashBoxTransfer.output_line.id)
  293. if (not lineOutput):
  294. return {
  295. 'state' : False,
  296. 'message': "No se pudo completar la operación."
  297. }
  298. if (lineOutput.statement_id.state == 'confirm'):
  299. return {
  300. 'state' : False,
  301. 'message': "No se pudo completar la operación, por que la caja de origen ya fue cerrada"
  302. }
  303. ### Line Input
  304. lineInput = self._get_statement_Line(cashBoxTransfer.input_line.id)
  305. if (not lineInput):
  306. return {
  307. 'state' : False,
  308. 'message': "No se pudo completar la operación."
  309. }
  310. if (lineInput.statement_id.state == 'confirm'):
  311. return {
  312. 'state' : False,
  313. 'message': "No se pudo completar la operación por que la caja destino ya fue cerrada"
  314. }
  315. ## updtae
  316. writeOutput = self._write_statement_line_transfer(lineOutput)
  317. ## unlink
  318. unlinkOutpu = self._unlink_statement_line_transfer(lineOutput)
  319. if (not unlinkOutpu):
  320. return {
  321. 'state' : False,
  322. 'message': "No se pudo completar la operación, error al eliminar la transferencia"
  323. }
  324. ## Update
  325. writeInput = self._write_statement_line_transfer(lineInput)
  326. ## Unlink
  327. unlinkInput = self._unlink_statement_line_transfer(lineInput)
  328. if (not unlinkInput):
  329. return {
  330. 'state' : False,
  331. 'message': "No se pudo completar la operación, error al eliminar la transferencia"
  332. }
  333. message = values['comment']+" \nEliminado por la caja "+str(statement.name)+" y por Usuario "+str(user.name)+" en "+str(date_server)
  334. writeTransfer = self._write_cash_box_transfer(cashBoxTransfer, message, user)
  335. if (not writeTransfer):
  336. return {
  337. 'state' : False,
  338. 'message': "No se pudo completar la operación"
  339. }
  340. return { 'state': True,
  341. 'message': 'Operación realizada con éxito'
  342. }
  343. '''
  344. ____ ____ ___ ___ _
  345. / ___|__ _ ___| __ ) _____ __ |_ _|_ __ / _ \ _ _| |_
  346. | | / _` / __| _ \ / _ \ \/ / | || '_ \ _____ | | | | | | | __|
  347. | |__| (_| \__ \ |_) | (_) > < | || | | | |_____| | |_| | |_| | |_
  348. \____\__,_|___/____/ \___/_/\_\ |___|_| |_| \___/ \__,_|\__|
  349. '''
  350. '''
  351. GET CashBox In
  352. '''
  353. @api.model
  354. def eiru_get_cash_box_in(self, id):
  355. return [{
  356. 'id': box_in.id,
  357. 'name': box_in.name,
  358. 'amount': box_in.amount,
  359. 'ref': box_in.ref,
  360. 'date': box_in.date,
  361. 'type': 'in',
  362. 'statement': {
  363. 'id': box_in.statement_id.id,
  364. 'name': box_in.statement_id.name,
  365. 'state': box_in.statement_id.state,
  366. 'typeJournal': box_in.statement_id.journal_id.type,
  367. 'date': box_in.statement_id.date,
  368. 'userId': box_in.statement_id.user_id.id,
  369. 'currency': {
  370. 'symbol': box_in.statement_id.currency.symbol,
  371. 'thousandsSeparator': box_in.statement_id.currency.thousands_separator,
  372. 'decimalSeparator': box_in.statement_id.currency.decimal_separator,
  373. 'decimalPlaces': box_in.statement_id.currency.decimal_places,
  374. }
  375. },
  376. 'statementLine': {
  377. 'id': box_in.line_id.id
  378. }
  379. } for box_in in self.env['cash.box.in'].search([('statement_id.id', '=', id)])]
  380. '''
  381. GET CashBox out
  382. '''
  383. @api.model
  384. def eiru_get_cash_box_out(self, id):
  385. return [{
  386. 'id': box_out.id,
  387. 'name': box_out.name,
  388. 'amount': box_out.amount,
  389. 'ref': box_out.ref,
  390. 'date': box_out.date,
  391. 'type': 'out',
  392. 'statement': {
  393. 'id': box_out.statement_id.id,
  394. 'name': box_out.statement_id.name,
  395. 'state': box_out.statement_id.state,
  396. 'typeJournal': box_out.statement_id.journal_id.type,
  397. 'date': box_out.statement_id.date,
  398. 'userId': box_out.statement_id.user_id.id,
  399. 'currency': {
  400. 'symbol': box_out.statement_id.currency.symbol,
  401. 'thousandsSeparator': box_out.statement_id.currency.thousands_separator,
  402. 'decimalSeparator': box_out.statement_id.currency.decimal_separator,
  403. 'decimalPlaces': box_out.statement_id.currency.decimal_places,
  404. }
  405. },
  406. 'statementLine': {
  407. 'id': box_out.line_id.id
  408. }
  409. } for box_out in self.env['cash.box.out'].search([('statement_id.id', '=', id)])]
  410. '''
  411. Create Statement Line
  412. '''
  413. def _create_statement_line_input_outup(self, statement,ref,amount,type,name):
  414. statementLine = {
  415. 'statement_id': statement.id,
  416. 'name': name,
  417. 'amount': type in ('input') and amount or -amount,
  418. 'ref': ref,
  419. 'account_id': statement.journal_id.internal_account_id.id,
  420. 'journal_id': statement.journal_id.id,
  421. 'is_deleted': True
  422. }
  423. line = self.env['account.bank.statement.line'].create(statementLine)
  424. return line
  425. '''
  426. Create cashBox input
  427. '''
  428. def create_cash_box_in_out(self, line, amount, ref, name, type):
  429. cash = {
  430. 'name': "%s %s" %((name),(line.statement_id.name)),
  431. 'amount': amount,
  432. 'ref': ref,
  433. 'date': line.date,
  434. 'line_id': line.id,
  435. 'statement_id': line.statement_id.id,
  436. }
  437. if (type =='input'):
  438. return self.env['cash.box.in'].create(cash)
  439. else:
  440. return self.env['cash.box.out'].create(cash)
  441. '''
  442. Create casbox input/output
  443. '''
  444. @api.model
  445. def create_cash_box_input_output(self, values):
  446. statement = self._get_statement_transfer(values['statementId'])
  447. if (not statement):
  448. return False
  449. name = values['type'] in ('input') and 'Entrada de Dinero' or 'Salida de Dinero'
  450. lineStatement = self._create_statement_line_input_outup(statement, values['ref'], values['amount'], values['type'], name)
  451. if (not lineStatement):
  452. return False
  453. casBox = self.create_cash_box_in_out(lineStatement, values['amount'], values['ref'], name, values['type'])
  454. if (not casBox):
  455. return False
  456. return {
  457. 'state': True
  458. }
  459. '''
  460. _ _ _ _ _ _ _ _ __ _
  461. | | | |_ __ | (_)_ __ | | __ ___ __ _ ___| |__ | |__ _____ __ (_)_ __ / /__ _ _| |_
  462. | | | | '_ \| | | '_ \| |/ / / __/ _` / __| '_ \| '_ \ / _ \ \/ / | | '_ \ / / _ \| | | | __|
  463. | |_| | | | | | | | | | < | (_| (_| \__ \ | | | |_) | (_) > < | | | | |/ / (_) | |_| | |_
  464. \___/|_| |_|_|_|_| |_|_|\_\ \___\__,_|___/_| |_|_.__/ \___/_/\_\ |_|_| |_/_/ \___/ \__,_|\__|
  465. '''
  466. '''
  467. get Cash box in - out
  468. '''
  469. def _get_cash_box_in_out(self, id, type):
  470. if (type == 'in'):
  471. return self.env['cash.box.in'].browse(id)
  472. if (type == 'out'):
  473. return self.env['cash.box.out'].browse(id)
  474. '''
  475. Unlink cash box in/out
  476. '''
  477. @api.model
  478. def unlink_cashbox_in_out(self, values):
  479. ### user
  480. user = self.env.user
  481. ### date server
  482. date_server = self.get_server_datetime()
  483. ### account Statement
  484. statement = self._get_statement_transfer(values['statementId'])
  485. if (not statement):
  486. return {
  487. 'state' : False,
  488. 'message': "No se pudo completar la operación."
  489. }
  490. ### cas box
  491. cashBox = self._get_cash_box_in_out(values['cashboxID'], values['type'])
  492. if (not cashBox):
  493. return {
  494. 'state' : False,
  495. 'message': "No se pudo completar la operación."
  496. }
  497. ### Line statement
  498. lineStatement = self._get_statement_Line(cashBox.line_id.id)
  499. if (not lineStatement):
  500. return {
  501. 'state' : False,
  502. 'message': "No se pudo completar la operación."
  503. }
  504. ## updtae line
  505. writelinet = self._write_statement_line_transfer(lineStatement)
  506. ## unlink line
  507. unlinkline = self._unlink_statement_line_transfer(lineStatement)
  508. if (not unlinkline):
  509. return {
  510. 'state' : False,
  511. 'message': "No se pudo completar la operación, error al eliminar la transferencia"
  512. }
  513. message = values['message']+" \nEliminado por la caja "+str(statement.name)+" y por Usuario "+str(user.name)+" en "+str(date_server)
  514. writeTransfer = self._write_cash_box_transfer(cashBox, message, user)
  515. if (not writeTransfer):
  516. return {
  517. 'state' : False,
  518. 'message': "No se pudo completar la operación"
  519. }
  520. return { 'state': True,
  521. 'message': 'Operación realizada con éxito'
  522. }
  523. '''
  524. ____ _ _ _ ___
  525. / ___|| |_ __ _| |_ ___ _ __ ___ ___ _ __ | |_ / _ \ _ __ ___ _ __
  526. \___ \| __/ _` | __/ _ \ '_ ` _ \ / _ \ '_ \| __| | | | | '_ \ / _ \ '_ \
  527. ___) | || (_| | || __/ | | | | | __/ | | | |_ | |_| | |_) | __/ | | |
  528. |____/ \__\__,_|\__\___|_| |_| |_|\___|_| |_|\__| \___/| .__/ \___|_| |_|
  529. |_|
  530. '''
  531. '''
  532. Get Statement Open
  533. '''
  534. @api.model
  535. def get_account_bank_statement_open(self,id):
  536. statement = self._get_statement_transfer(id)
  537. if (not statement):
  538. return False
  539. return [{
  540. 'id': open.id,
  541. 'name': open.name
  542. } 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')])]
  543. '''
  544. Open cashBox
  545. '''
  546. @api.model
  547. def account_bank_statement_open_cashbox(self, id):
  548. statement = self._get_statement_transfer(id)
  549. return statement.button_open()
  550. @api.model
  551. def account_bank_statement_open(self, id):
  552. statement = self._get_statement_transfer(id)
  553. cashBoxConfirm = self._get_cashbox_statement_confirm(statement)
  554. for casBox in cashBoxConfirm:
  555. name = "SALDO ANTERIOR /"+str(casBox.statement_id.name)
  556. lineTransfer = self._create_statement_line_transfer(statement, name, (casBox.amount_next_open), 'Apertura')
  557. # lineTransfer = self._create_statement_line_transfer(statement, name, abs(casBox.amount_next_open), 'Apertura')
  558. if (not lineTransfer):
  559. return {
  560. 'state': False,
  561. 'message': "Error al registrar el saldo anterior."
  562. }
  563. confirmCasBox = self.env['cashbox.statement.confirm'].browse(casBox.id)
  564. values = {
  565. 'statement_open': statement.id,
  566. 'line_open': lineTransfer.id,
  567. 'state_avaliable': False
  568. }
  569. confirmCasBox = self._writer_cashbox_statement_confirm(confirmCasBox,values)
  570. return True
  571. '''
  572. get cashbox.statement.confirm
  573. '''
  574. def _get_cashbox_statement_confirm(self, statement):
  575. return self.env['cashbox.statement.confirm'].search([
  576. ('statement_id.type_statement.id', '=', statement.type_statement.id),
  577. ('user_statement', '=', statement.user_id.id),
  578. ('journal_id', '=', statement.journal_id.id),
  579. ('state_avaliable', '=', True),
  580. # ('amount_next_open', '>', 0.0),
  581. ('statement_id.id', '!=', statement.id)])
  582. '''
  583. writer casbox statement confirm
  584. '''
  585. def _writer_cashbox_statement_confirm(self, casbox, values):
  586. return casbox.write(values)
  587. '''
  588. method Open CashBox
  589. '''
  590. @api.multi
  591. def button_open(self):
  592. self.account_bank_statement_open(self.id)
  593. return super(AccountBankStatementUtility, self).button_open()
  594. '''
  595. _ _ _ _ _ ____ _ _ _
  596. | | | |_ __ | (_)_ __ | | __ / ___|| |_ __ _| |_ ___ _ __ ___ ___ _ __ | |_
  597. | | | | '_ \| | | '_ \| |/ / \___ \| __/ _` | __/ _ \ '_ ` _ \ / _ \ '_ \| __|
  598. | |_| | | | | | | | | | < ___) | || (_| | || __/ | | | | | __/ | | | |_
  599. \___/|_| |_|_|_|_| |_|_|\_\ |____/ \__\__,_|\__\___|_| |_| |_|\___|_| |_|\__|
  600. '''
  601. '''
  602. Get Statement
  603. '''
  604. @api.model
  605. def eiru_get_bank_statement_unlink(self, id):
  606. return [{
  607. 'id': statement.id,
  608. 'name': statement.name,
  609. 'state': statement.state,
  610. 'currencystatement': {
  611. 'id': statement.currency.id,
  612. 'symbol': statement.currency.symbol,
  613. 'rate': statement.currency.rate,
  614. 'thousandsSeparator': statement.currency.thousands_separator,
  615. 'decimalSeparator': statement.currency.decimal_separator,
  616. 'decimalPlaces': statement.currency.decimal_places,
  617. 'position': statement.currency.position,
  618. },
  619. 'lineStatement': [{
  620. 'id': line.id,
  621. 'name': line.name,
  622. 'ref': line.ref,
  623. 'amount': line.amount,
  624. 'date': line.date,
  625. 'casBoxTransfer': [{
  626. 'id': transfer.id,
  627. 'name': transfer.name,
  628. 'amount': transfer.amount,
  629. 'ref': transfer.ref,
  630. 'date': transfer.date,
  631. 'inputStatement': transfer.input_statement.id,
  632. 'outputStatement': transfer.output_statement.id,
  633. 'inputStatementState': transfer.input_statement.state,
  634. 'outputStatementState': transfer.output_statement.state
  635. }for transfer in self.env['cash.box.transfer'].search(['|',('input_line.id', '=', line.id), ('output_line.id', '=', line.id)])],
  636. 'casBoxIn': [{
  637. 'id': boxIn.id,
  638. 'name': boxIn.name,
  639. 'amount': boxIn.amount,
  640. 'ref': boxIn.ref,
  641. 'date': boxIn.date,
  642. 'active': boxIn.active
  643. }for boxIn in self.env['cash.box.in'].search([('line_id.id', '=', line.id)])],
  644. 'casBoxOut': [{
  645. 'id': boxOut.id,
  646. 'name': boxOut.name,
  647. 'amount': boxOut.amount,
  648. 'ref': boxOut.ref,
  649. 'date': boxOut.date,
  650. 'active': boxOut.active
  651. }for boxOut in self.env['cash.box.out'].search([('line_id.id', '=', line.id)])]
  652. }for line in statement.line_ids]
  653. }for statement in self.env['account.bank.statement'].browse(id)]
  654. '''
  655. Unlink Line Statement
  656. '''
  657. def _eiru_unlink_statement_line(self, line):
  658. '''
  659. Eliminar las lineas de la caja.
  660. <-> Actualizar la linea.
  661. <-> Cancelar la linea.
  662. <-> Eliminar la linea.
  663. <-> Retur True
  664. '''
  665. ### Update Line
  666. writeLine = self._write_statement_line_transfer(line)
  667. ### Cancelar Line
  668. lineCancel = line.cancel()
  669. ### Unlink Line
  670. lineUnlink = line.unlink()
  671. return True
  672. '''
  673. Update CashBox
  674. '''
  675. def _eiru_write_cashbox(self, cashbox, values):
  676. return cashbox.write(values)
  677. '''
  678. Unlink Statement
  679. '''
  680. @api.model
  681. def eiru_unlink_statement(self, id):
  682. statement = self._get_statement_transfer(id)
  683. if (not statement):
  684. return {
  685. 'state': False,
  686. 'message': 'Error en obtener el registro de caja.'
  687. }
  688. ## User
  689. user = self.env.user
  690. ## date
  691. date_server = self.get_server_datetime()
  692. ### FIlter line ids
  693. statementLines= map(lambda x: x.id, statement.line_ids)
  694. # Get casbox Transfer
  695. cashBoxTransfer = self.env['cash.box.transfer'].search(['|',('input_statement.id', '=', statement.id),('output_statement.id', '=', statement.id)])
  696. # Get cashBox Input
  697. cashBoxIn = self.env['cash.box.in'].search([('statement_id.id', '=', statement.id)])
  698. # Get cashBox Output
  699. cashBoxOut = self.env['cash.box.out'].search([('statement_id.id', '=', statement.id)])
  700. # confirm
  701. cashBoxConfirm = self.env['cashbox.statement.confirm'].search([('statement_id.id', '=', statement.id)])
  702. cashBoxConfirmOpen = self.env['cashbox.statement.confirm'].search([('statement_open.id', '=', statement.id)])
  703. ### Transfer
  704. stateTransfer = 'open'
  705. ref = ''
  706. for transfer in cashBoxTransfer:
  707. if (transfer.input_statement):
  708. if (transfer.input_statement.state == 'confirm'):
  709. stateTransfer = transfer.input_statement.state
  710. ref += str(' / ')+ transfer.output_statement.name if (ref) else transfer.output_statement.name
  711. if (transfer.output_statement):
  712. if (transfer.output_statement.state == 'confirm'):
  713. stateTransfer = transfer.output_statement.state
  714. ref += str(' / ')+ transfer.output_statement.name if (ref) else transfer.output_statement.name
  715. if (stateTransfer == 'confirm'):
  716. return {
  717. 'state': False,
  718. 'message': 'Existe caja relacionada que ya están cerrada Ref('+str(ref)+')'
  719. }
  720. message_deleted = 'La caja '+str(statement.name)+', Fue eliminada por '+str(user.name)+' en '+str(date_server)
  721. messageDeletedCashBoxConfirm = {
  722. 'active': False,
  723. 'state_avaliable': False,
  724. 'message_deleted': message_deleted
  725. }
  726. messageDeletedCashBoxConfirmOpen = {
  727. 'active': True,
  728. 'state_avaliable': True,
  729. 'message_deleted': message_deleted
  730. }
  731. messageDeletedCashBox = {
  732. 'active': False,
  733. 'message_deleted': message_deleted
  734. }
  735. for transfer in cashBoxTransfer:
  736. lineStatement = transfer.input_line.id in statementLines and transfer.output_line.id or transfer.input_line.id
  737. bankLine = self.env['account.bank.statement.line'].browse(lineStatement)
  738. if (not bankLine):
  739. return {
  740. 'state': False,
  741. 'message': 'Error, No fue posible localizar una de las lineas de la transferencia.'
  742. }
  743. ### Verificar el estado de la caja
  744. if (bankLine.statement_id.state == 'confirm'):
  745. return {
  746. 'state': False,
  747. 'message': 'Error, Una de las caja ya esta cerrada.'
  748. }
  749. ### Unlink Line Statement
  750. lineUnlink = self._eiru_unlink_statement_line(bankLine)
  751. accountCasboxTransfer = self.env['cash.box.transfer'].browse(transfer.id)
  752. if (not accountCasboxTransfer):
  753. return {
  754. 'state': False,
  755. 'message': 'Error, No fue posible localizar la transferencia.'
  756. }
  757. ### Update CashBox transfer
  758. boxTransfer = self._eiru_write_cashbox(accountCasboxTransfer,messageDeletedCashBox)
  759. if (cashBoxIn):
  760. boxIn = self._eiru_write_cashbox(cashBoxIn,messageDeletedCashBox)
  761. if (cashBoxOut):
  762. boxOut = self._eiru_write_cashbox(cashBoxOut,messageDeletedCashBox)
  763. if (cashBoxConfirm):
  764. confirm = self._eiru_write_cashbox(cashBoxConfirm,messageDeletedCashBoxConfirm)
  765. if (cashBoxConfirmOpen):
  766. confirmOpen = self._eiru_write_cashbox(cashBoxConfirmOpen,messageDeletedCashBoxConfirmOpen)
  767. ### Cancel statement
  768. cancelStatement = self.eiru_button_cancel(statement)
  769. ### Eliminar las lineas
  770. for line in statement.line_ids:
  771. writeLine = self._write_statement_line_transfer(line)
  772. lineUnlink = line.unlink()
  773. ## Unlink Statement
  774. unlinkStatement = statement.unlink()
  775. return {
  776. 'state': True,
  777. 'message': 'Operacion exitosa'
  778. }