浏览代码

[FIX] Eliminar Transferencia

adrielso 6 年之前
父节点
当前提交
14c7f91879

+ 73 - 49
controllers/account_bank_statement.py

@@ -74,6 +74,10 @@ def get_account_bank_statement( journalIds=None):
 '''Create Account Bank Statement '''
 def create_account_bank_statement(data):
     make_info_log('Create Account Bank Statement')
+    from account_bank_statement_line import get_line_statement
+    from res_users import get_name_users
+    from account_journal import get_name_journal, get_currencie_journal
+    from account_bank_statement_type import get_name_statement_type
 
     from account_bank_statement_config import get_bank_statement_config
 
@@ -107,7 +111,6 @@ def create_account_bank_statement(data):
             'state': False,
             'message': 'No fue posible abrir la caja '
         }
-
     return {
         'state': openStatement,
         'message': 'Caja creada con éxito',
@@ -116,56 +119,77 @@ def create_account_bank_statement(data):
             'name': statement.name,
             'date': statement.date,
             'state': statement.state,
-            'balanceEnd': statement.balance_end,
-            'user': {
-                'id': statement.user_id.id,
-                'name': statement.user_id.name,
-                'displayName': statement.user_id.display_name
-            },
-            'userSession': request.env.user.id,
-            'journal': {
-                'id': statement.journal_id.id,
-                'name': statement.journal_id.name,
-                'displayName': statement.journal_id.display_name,
-                'code': statement.journal_id.code,
-                'cashControl': statement.journal_id.cash_control,
-                'type': statement.journal_id.type,
-                'currency': {
-                    'id': statement.journal_id.currency.id,
-                    'name': statement.journal_id.currency.name,
-                    'displayName': statement.journal_id.currency.display_name
-                }
-            },
-            'line': [{
-                'id': line.id,
-                'date': line.date,
-                'name': line.name,
-                'ref': line.ref,
-                'amount': line.amount,
-                'patner':{
-                    'id': line.partner_id.id,
-                    'name': line.partner_id.name,
-                    'displayName': line.partner_id.display_name
-                },
-            } for line in statement.line_ids],
-            'typeStatement': {
-                'id': statement.type_statement.id,
-                'name': statement.type_statement.name,
-                'code': statement.type_statement.code
-            },
-            'currency':{
-                'id': statement.currency.id,
-                'name': statement.currency.display_name,
-                'base': statement.currency.base,
-                'symbol': statement.currency.symbol,
-                'position': statement.currency.position,
-                'rateSilent': statement.currency.rate_silent,
-                'decimalSeparator': statement.currency.decimal_separator,
-                'decimalPlaces': statement.currency.decimal_places,
-                'thousandsSeparator': statement.currency.thousands_separator
-            }
+            'balanceEnd': statement.balance_end or 0,
+            'userId': statement.user_id.id,
+            'userName': get_name_users(statement.user_id.id),
+            'journalId': statement.journal_id.id,
+            'journalName': get_name_journal(statement.journal_id.id),
+            'currency': get_currencie_journal(statement.journal_id.id),
+            'typeStatementId': statement.type_statement.id,
+            'typeStatementName': get_name_statement_type(statement.type_statement.id),
+            'userSessionID': request.env.user.id,
+            'userSessionName': request.env.user.name,
+            'lines': get_line_statement(statement.id)
         }
     }
+    # return {
+    #     'state': openStatement,
+    #     'message': 'Caja creada con éxito',
+    #     'data' : {
+    #         'id': statement.id,
+    #         'name': statement.name,
+    #         'date': statement.date,
+    #         'state': statement.state,
+    #         'balanceEnd': statement.balance_end,
+    #         'user': {
+    #             'id': statement.user_id.id,
+    #             'name': statement.user_id.name,
+    #             'displayName': statement.user_id.display_name
+    #         },
+    #         'userSession': request.env.user.id,
+    #         'journal': {
+    #             'id': statement.journal_id.id,
+    #             'name': statement.journal_id.name,
+    #             'displayName': statement.journal_id.display_name,
+    #             'code': statement.journal_id.code,
+    #             'cashControl': statement.journal_id.cash_control,
+    #             'type': statement.journal_id.type,
+    #             'currency': {
+    #                 'id': statement.journal_id.currency.id,
+    #                 'name': statement.journal_id.currency.name,
+    #                 'displayName': statement.journal_id.currency.display_name
+    #             }
+    #         },
+    #         'line': [{
+    #             'id': line.id,
+    #             'date': line.date,
+    #             'name': line.name,
+    #             'ref': line.ref,
+    #             'amount': line.amount,
+    #             'patner':{
+    #                 'id': line.partner_id.id,
+    #                 'name': line.partner_id.name,
+    #                 'displayName': line.partner_id.display_name
+    #             },
+    #         } for line in statement.line_ids],
+    #         'typeStatement': {
+    #             'id': statement.type_statement.id,
+    #             'name': statement.type_statement.name,
+    #             'code': statement.type_statement.code
+    #         },
+    #         'currency':{
+    #             'id': statement.currency.id,
+    #             'name': statement.currency.display_name,
+    #             'base': statement.currency.base,
+    #             'symbol': statement.currency.symbol,
+    #             'position': statement.currency.position,
+    #             'rateSilent': statement.currency.rate_silent,
+    #             'decimalSeparator': statement.currency.decimal_separator,
+    #             'decimalPlaces': statement.currency.decimal_places,
+    #             'thousandsSeparator': statement.currency.thousands_separator
+    #         }
+    #     }
+    # }
 
 ''' confirm bank Statement '''
 def closing_statement(data):

+ 60 - 8
controllers/account_bank_statement_line.py

@@ -40,14 +40,59 @@ def create_statement_line(values):
 ''' Modify statement line '''
 def modify_statement_line(value):
     ''' DELETED '''
+    from cashbox_transfer import verify_transfer, writer_cashbox_transfer
+    from server_datetime import get_date
+
+    messageDelet = ""
+    messageWrite = ""
+
     if (value['linesDeleted']):
         make_info_log('Unlink Statement Line')
         for line in request.env[_MODEL].search([('id', 'in', value['linesDeleted'])]):
-            if(line.is_deleted):
-                lineWrite={'is_deleted': False}
-                write_statement_line(line,lineWrite)
 
-            unlink_statement_line(line)
+            ## line Transferencia.
+            transfer = verify_transfer(line.id)
+            if (transfer):
+                if (transfer['statementConfirm']):
+                    messageDelet += "No se puede eliminar la linea (%s), Obs. (%s)" %(line.name, transfer['messageConfirm'])
+                    continue
+                ## Unlink Lines input
+                unlink_statement_line(transfer['inputLine'])
+                ## Unlink Lines output
+                unlink_statement_line(transfer['outputLine'])
+                ## Writer Transfer
+                transferWriter = {
+                    'message_deleted': "Transferencia eliminada por %s en %s ,caja %s" %((request.env.user.name), get_date(), line.statement_id.name),
+                    'active': False,
+                    'write_uid': request.env.user.id
+                }
+                writer_cashbox_transfer(transfer['transferId'],transferWriter)
+
+            ## line Input
+
+            ## line Output
+
+            ## line Normal
+
+                # if(line.is_deleted):
+                #     lineWrite={'is_deleted': False}
+                #     write_statement_line(line,lineWrite)
+                #
+                # unlink_statement_line(line)
+
+    # import web_pdb; web_pdb.set_trace()
+
+            # if(line.is_deleted):
+            #     lineWrite={'is_deleted': False}
+            #     write_statement_line(line,lineWrite)
+            #
+            # unlink_statement_line(line)
+
+            # 'transferId'
+            # 'statementConfirm'
+            # 'messageConfirm'
+            # 'inputLine'
+            # 'outputLine'
 
     ''' UPDATE '''
     if (value['lineUpdate']):
@@ -66,12 +111,19 @@ def modify_statement_line(value):
 
     return {
         'state': True,
-        'message': 'Proceso finalizado.'
+        'message': '%s %s' %(messageDelet, messageWrite)
     }
 
-''' Unlink '''
-def unlink_statement_line(line):
-    return line.sudo().unlink()
+''' UnLink '''
+def unlink_statement_line(lineId):
+    lineUnlink = request.env[_MODEL].browse(lineId)
+    if (not lineUnlink):
+        return False
+
+    if(lineUnlink.is_deleted):
+        lineUnlink.sudo().write({'is_deleted': False})
+
+    return lineUnlink.sudo().unlink()
 
 ''' Write '''
 def write_statement_line(line, value):

+ 158 - 0
controllers/cashbox_transfer.py

@@ -73,3 +73,161 @@ def create_cashbox_transfer(data):
         }
 
     return result
+
+
+''' Verify trasnfer for line'''
+def verify_transfer(line):
+    transfer = request.env[_MODEL].search(['|',('input_line.id','=',line),('output_line.id','=',line)])
+    if (not transfer):
+        return {}
+
+    messageConfirm = ""
+    statementConfirm = False
+
+    if (transfer.input_statement.state == 'confirm'):
+        messageConfirm += "La caja origen (%s), ya esta cerrada." %(transfer.input_statement.name)
+        statementConfirm = True
+
+    if (transfer.output_statement.state == 'confirm'):
+        messageConfirm += "La caja destino (%s), ya esta cerrada." %(transfer.output_statement.name)
+        statementConfirm = True
+
+    return {
+        'transferId': transfer.id,
+        'statementConfirm': statementConfirm,
+        'messageConfirm': messageConfirm,
+        'inputLine': transfer.input_line.id,
+        'outputLine': transfer.output_line.id,
+    }
+
+def writer_cashbox_transfer(id, value):
+    transfer = request.env[_MODEL].browse(id)
+    if (not transfer):
+        return False
+
+    return transfer.sudo().write(value)
+
+'''
+          # _   _       _ _       _      _____                     __
+         # | | | |_ __ | (_)_ __ | | __ |_   _| __ __ _ _ __  ___ / _| ___ _ __
+         # | | | | '_ \| | | '_ \| |/ /   | || '__/ _` | '_ \/ __| |_ / _ \ '__|
+         # | |_| | | | | | | | | |   <    | || | | (_| | | | \__ \  _|  __/ |
+          # \___/|_| |_|_|_|_| |_|_|\_\   |_||_|  \__,_|_| |_|___/_|  \___|_|
+        # 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'
+        }
+'''

+ 1 - 1
src/components/common/CardGrid.vue

@@ -213,7 +213,7 @@
 <style lang="sass">
     .card-grid-wrapper
         width: 100%
-        height: calc(100% - 50px)
+        height: calc(100% - 90px)
         margin-top: 10px
         overflow-y: auto
         &::-webkit-scrollbar

+ 2 - 1
src/components/steps/CardGridItem.vue → src/components/common/CardGridItem.vue

@@ -8,7 +8,8 @@
 </template>
 
 <script>
-    import CardItem from '@/components/steps/CardItem'
+    import CardItem from '@/components/common/CardItem'
+    
     export default {
         props: {
             items: {

+ 1 - 1
src/components/common/CardGridStatement.vue

@@ -141,7 +141,7 @@
 <style lang="sass">
     .card-grid-wrapper-statement
         width: 100%
-        height: calc(100% - 50px)
+        height: calc(100% - 90px)
         margin-top: 10px
         overflow-y: auto
         &::-webkit-scrollbar

+ 0 - 0
src/components/steps/CardItem.vue → src/components/common/CardItem.vue


+ 4 - 0
src/components/common/index.js

@@ -8,11 +8,15 @@ import Spinner from './Spinner'
 import SwitchButtonInput from './SwitchButtonInput'
 import Ticket from './Ticket'
 import CardGridStatement from './CardGridStatement'
+import CardGridItem from './CardGridItem'
+import CartItem from './CartItem'
 
 export {
     CardGrid,
     CardGridStatement,
     DropdownSearcher,
+    CardGridItem,
+    CartItem,
     InputDropdown,
     InputSelect,
     LoadingOverlay,

+ 2 - 2
src/components/steps/StatementModify.vue

@@ -32,8 +32,8 @@
 
 <script>
     import { mapGetters, mapActions } from 'vuex'
-    import {SwitchButtonInput, InputDropdown } from '../common'
-    import CardGridItem from '@/components/steps/CardGridItem'
+    import {SwitchButtonInput, InputDropdown, CardGridItem } from '../common'
+    // import CardGridItem from '@/components/steps/CardGridItem'
     import StatementLineModal from '../modal/StatementLineModal'
 
     export default {

+ 3 - 1
src/components/steps/StatementStep.vue

@@ -36,8 +36,9 @@
                 )
             transition(name='slide-fade')
                 statement-action-form(
-                    v-if='!!selectedStatement'
+                    v-if='!!getStatementActions'
                 )
+                //- v-if='!!selectedStatement'
 </template>
 
 <script>
@@ -66,6 +67,7 @@
             'selectedUserName',
             'selectedJournalName',
             'dateStatement',
+            'getStatementActions'
         ]),
         methods: {
             addNewStatment () {

+ 10 - 6
src/store/modules/statementConfig.js

@@ -6,7 +6,7 @@ const initialState = {
     actionInputCashbox: false,
     actionOutputCashbox: false,
     actionStatementConfirm: false,
-    actionModifyStatement: true
+    actionModifyStatement: false
 }
 
 const state = {
@@ -45,6 +45,9 @@ const getters = {
     actionModifyStatement(state) {
         return  state.actionModifyStatement
     },
+    getStatementActions(state) {
+        return !!state.actionTransfer || !!state.actionInputCashbox || !!state.actionOutputCashbox || !!state.actionStatementConfirm || !!state.actionModifyStatement ? true : false
+    },
 }
 
 const mutations = {
@@ -63,27 +66,28 @@ const mutations = {
     setAllowedActions(state, payload) {
 
         let config = !payload ? null :state.configStatemen
-        if (!config){
+        console.log(payload);
+        if ((!config) || (payload.state === "confirm")){
             state.actionTransfer = false
             state.actionInputCashbox = false
             state.actionOutputCashbox = false
             state.actionStatementConfirm = false
+            state.actionModifyStatement = false
             // !! mas acciones agregar aqui
             return
         }
 
+        state.actionModifyStatement = true
+
         //  @Transfer
         let resultTransfer = !!config.transfer.userIds.find(item => item === payload.userSessionID) && !!config.transfer.statementIds.find(item => item === payload.typeStatementId)
         state.actionTransfer = resultTransfer
-
         // @Input
         let resultInput = !!config.inputCashBox.userIds.find(item => item === payload.userSessionID) && !!config.inputCashBox.statementIds.find(item => item === payload.typeStatementId)
         state.actionInputCashbox = resultInput
-
         // @Output
         let resultOutput = !!config.outputCashBox.userIds.find(item => item === payload.userSessionID) && !!config.outputCashBox.statementIds.find(item => item === payload.typeStatementId)
         state.actionOutputCashbox = resultOutput
-
         // @Confirm
         let resultConfirm = !!config.statementConfirm.userIds.find(item => item === payload.userSessionID)
         state.actionStatementConfirm = resultConfirm
@@ -99,7 +103,7 @@ const actions = {
     verifyActionCashbox({ getters, commit }, payload) {
         commit('setAllowedActions', payload)
     },
-    resetStatementConfig({commit}){
+    resetStatementConfig({commit}) {
         commit('setStatementConfig',[])
         commit('setLoadingStatementConfig', false)
         commit('setConfigStatemen', [])