odoo10_addons

Check-in [fd559f3ab9]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:trial_balance_co: se permite generar agrupado por account.code, usando los niveles de la contabilidad colombiana
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | enterprise
Files: files | file ages | folders
SHA3-256: fd559f3ab94e088ac18cb87d263eb980aff479f173a8a8939393cc93014f68fa
User & Date: bit4bit 2019-02-21 02:20:23
Context
2019-03-08
00:34
se fuerza id de account a enteror check-in: d72a82ca28 user: bit4bit tags: enterprise
2019-02-21
02:20
trial_balance_co: se permite generar agrupado por account.code, usando los niveles de la contabilidad colombiana check-in: fd559f3ab9 user: bit4bit tags: enterprise
2019-02-20
21:57
se renombra anexo_al_balance a trial_balance_co check-in: fc597a82cd user: bit4bit tags: enterprise
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to trial_balance_co/i18n/es.po.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid ": Partner Trial Balance"
msgstr ": Anexo al Balance"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid "<strong>Date from :</strong>"
msgstr "<strong>Fecha desde:</strong>"

#. module: trial_balance_co
................................................................................
msgid "Last Updated on"
msgstr "Última actualización el"

#. module: trial_balance_co
#: model:ir.actions.act_window,name:trial_balance_co.action_account_balance_menu
#: model:ir.ui.menu,name:trial_balance_co.menu_general_Balance_report
msgid "Partner Trial Balance"
msgstr "Anexo al Balance"

#. module: trial_balance_co
#: model:ir.model,name:trial_balance_co.model_trial_balance_co_report_partner_trial_balance
msgid "Partner Trial Balance Report"
msgstr "Reporte Anexos al Balance"

#. module: trial_balance_co
#: model:ir.actions.report.xml,name:trial_balance_co.action_report_partner_trial_balance
msgid "Report Partner Trial Balance"
msgstr "Report Partner Trial Balance"

#. module: trial_balance_co







|







 







|




|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid ": Partner Trial Balance"
msgstr ": Balance de Comprobación"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid "<strong>Date from :</strong>"
msgstr "<strong>Fecha desde:</strong>"

#. module: trial_balance_co
................................................................................
msgid "Last Updated on"
msgstr "Última actualización el"

#. module: trial_balance_co
#: model:ir.actions.act_window,name:trial_balance_co.action_account_balance_menu
#: model:ir.ui.menu,name:trial_balance_co.menu_general_Balance_report
msgid "Partner Trial Balance"
msgstr "Balance de Comprobación"

#. module: trial_balance_co
#: model:ir.model,name:trial_balance_co.model_trial_balance_co_report_partner_trial_balance
msgid "Partner Trial Balance Report"
msgstr "Reporte Balance de Comprobación"

#. module: trial_balance_co
#: model:ir.actions.report.xml,name:trial_balance_co.action_report_partner_trial_balance
msgid "Report Partner Trial Balance"
msgstr "Report Partner Trial Balance"

#. module: trial_balance_co

Changes to trial_balance_co/i18n/es_CO.po.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid ": Partner Trial Balance"
msgstr ": Anexo al Balance"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid "<strong>Date from :</strong>"
msgstr "<strong>Fecha desde:</strong>"

#. module: trial_balance_co
................................................................................
msgid "Last Updated on"
msgstr "Última actualización el"

#. module: trial_balance_co
#: model:ir.actions.act_window,name:trial_balance_co.action_account_balance_menu
#: model:ir.ui.menu,name:trial_balance_co.menu_general_Balance_report
msgid "Partner Trial Balance"
msgstr "Anexo al Balance"

#. module: trial_balance_co
#: model:ir.model,name:trial_balance_co.model_trial_balance_co_report_partner_trial_balance
msgid "Partner Trial Balance Report"
msgstr "Reporte Anexos al Balance"

#. module: trial_balance_co
#: model:ir.actions.report.xml,name:trial_balance_co.action_report_partner_trial_balance
msgid "Report Partner Trial Balance"
msgstr "Report Partner Trial Balance"

#. module: trial_balance_co







|







 







|




|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid ": Partner Trial Balance"
msgstr ": Balance de Comprobación"

#. module: trial_balance_co
#: model:ir.ui.view,arch_db:trial_balance_co.report_partner_trial_balance
msgid "<strong>Date from :</strong>"
msgstr "<strong>Fecha desde:</strong>"

#. module: trial_balance_co
................................................................................
msgid "Last Updated on"
msgstr "Última actualización el"

#. module: trial_balance_co
#: model:ir.actions.act_window,name:trial_balance_co.action_account_balance_menu
#: model:ir.ui.menu,name:trial_balance_co.menu_general_Balance_report
msgid "Partner Trial Balance"
msgstr "Balance de Comprobación"

#. module: trial_balance_co
#: model:ir.model,name:trial_balance_co.model_trial_balance_co_report_partner_trial_balance
msgid "Partner Trial Balance Report"
msgstr "Reporte Balance de Comprobación"

#. module: trial_balance_co
#: model:ir.actions.report.xml,name:trial_balance_co.action_report_partner_trial_balance
msgid "Report Partner Trial Balance"
msgstr "Report Partner Trial Balance"

#. module: trial_balance_co

Changes to trial_balance_co/report/balance.py.

1
2
3
4

5
6
7
8
9
10
11
..
32
33
34
35
36
37
38

























39
40
41
42
43
44
45
..
56
57
58
59
60
61
62
63








































64
65
66
67
68
69

70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
...
166
167
168
169
170
171
172

173


174





175
176
177
178
179
180
181
182
183
184
185
import time
import copy
import dateutil.parser
from datetime import timedelta


from odoo import api , models, _
from odoo.exceptions import UserError


class ReportPartnerTrialBalance(models.AbstractModel):
    """
................................................................................
        # compute the balance, debit and credit for the provided accounts
        request = ("SELECT account_id AS id, SUM(debit) AS debit, SUM(credit) AS credit, (SUM(debit) - SUM(credit)) AS balance" +\
                   " FROM " + tables + " WHERE account_id IN %s " + filters + " GROUP BY account_id")
        params = (tuple(accounts.ids),) + tuple(where_params)
        self.env.cr.execute(request, params)
        for row in self.env.cr.dictfetchall():
            account_result[row.pop('id')] = row

























        return account_result

    def _fetch_moves_by_account_id_and_partner_id(self, accounts, default_partner_id):
        account_result = {}
        indexes = {}
        (tables, where_clause, where_params, wheres) = self._prepare_sql()
        filters = " AND ".join(wheres)
................................................................................
            if not rid in account_result:
                account_result[rid] = []
            account_result[rid].append(row)
            assert key not in indexes or (key in indexes and indexes[key] == 0 )
            indexes[key] = len(account_result[rid]) - 1
        
        return (account_result, indexes)
        








































    #tomado de: account/report/account_balance.py
    def _get_accounts(self, used_context, accounts, display_account, default_partner_id):
        """ compute the balance, debit and credit for the provided accounts
            :Arguments:
                `accounts`: list of accounts record,
                `display_account`: it's used to display either all accounts or those accounts which balance is > 0

            :Returns a list of dictionary of Accounts with following key and value
                `name`: Account name,
                `code`: Account code,
                `credit`: total amount of credit,
                `debit`: total amount of debit,
                `balance`: total amount of balance,
                `type`: `line` or `subline` or `subtotal`
        """


        account_result = self._fetch_moves_by_account_id(accounts)
        (account_partner_result, _) = self._fetch_moves_by_account_id_and_partner_id(accounts, default_partner_id)
        
        date_to = dateutil.parser.parse(used_context['date_from']) - timedelta(days=1)
        used_context_previous = copy.copy(used_context)
        used_context_previous.update({'date_to': date_to, 'date_from': False})
        account_result_previous = self.with_context(used_context_previous)._fetch_moves_by_account_id(accounts)
        (account_partner_result_previous, account_partner_result_previous_idx) = self.with_context(used_context_previous)._fetch_moves_by_account_id_and_partner_id(accounts, default_partner_id)

        #query all partners
        partners = {}
        for partner in self.env['res.partner'].search([]):
            partners[partner.id] = partner

        def get_partners(account_id):
            vlist = []
            if account_id in account_partner_result.keys():
                    for account_partner in account_partner_result[account.id]:
                        res_partner = dict((fn, 0.0) for fn in ['balance_prev', 'credit', 'debit', 'balance', 'balance_total'])
                        partner_id = account_partner.get('partner_id')
                        if partner_id not in partners:
                            partner_id = default_partner_id
                        
                        if partner_id not in partners:
                            raise UserError(_('Asociado en Elementos de diaro con id %s no ubicado en Asociados, indique un partner por defecto') % (str(partner_id)))
................................................................................
                        res_partner['type'] = 'subline'
                        res_partner['code'] = partners[partner_id].vat
                        res_partner['name'] = partners[partner_id].name
                        res_partner['debit'] = account_partner.get('debit')
                        res_partner['credit'] = account_partner.get('credit')
                        res_partner['balance'] = account_partner.get('balance')
                        res_partner['balance_total'] = res_partner['balance']
                        
                        key = '%d.%d' % (account_id, partner_id)

                        if account_id in account_partner_result_previous and key in account_partner_result_previous_idx:
                            previous = account_partner_result_previous[account_id][account_partner_result_previous_idx[key]]
                            res_partner['balance_prev'] = previous['balance']
                            res_partner['balance_total'] = previous['balance'] + res_partner['balance']
                            
                        vlist.append(res_partner)
            return vlist
................................................................................
        if not data.get('form') or not self.env.context.get('active_model'):
            raise UserError(_("Form content is missing, this report cannot be printed."))

        self.model = self.env.context.get('active_model')
        docs = self.env[self.model].browse(self.env.context.get('active_ids', []))
        display_account = data['form'].get('display_account')
        default_partner = data['form'].get('default_unknown_partner_id')

        accounts = docs if self.model == 'account.account' else self.env['account.account'].search([])


        account_res = self.with_context(data['form'].get('used_context'))._get_accounts(data['form'].get('used_context'), accounts, display_account, default_partner)






        docargs = {
            'doc_ids': self.ids,
            'doc_model': self.model,
            'data': data['form'],
            'docs': docs,
            'time': time,
            'Accounts': account_res,
        }

        return self.env['report'].render('trial_balance_co.report_partner_trial_balance', docargs)




>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>









>


<





>








|







 







<

>







 







>

>
>
|
>
>
>
>
>











1
2
3
4
5
6
7
8
9
10
11
12
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
...
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import time
import copy
import dateutil.parser
from datetime import timedelta
import collections

from odoo import api , models, _
from odoo.exceptions import UserError


class ReportPartnerTrialBalance(models.AbstractModel):
    """
................................................................................
        # compute the balance, debit and credit for the provided accounts
        request = ("SELECT account_id AS id, SUM(debit) AS debit, SUM(credit) AS credit, (SUM(debit) - SUM(credit)) AS balance" +\
                   " FROM " + tables + " WHERE account_id IN %s " + filters + " GROUP BY account_id")
        params = (tuple(accounts.ids),) + tuple(where_params)
        self.env.cr.execute(request, params)
        for row in self.env.cr.dictfetchall():
            account_result[row.pop('id')] = row

        return account_result

    def _fetch_moves_by_account_code(self, accounts):
        account_result = collections.OrderedDict()
        moves = self._fetch_moves_by_account_id(accounts)
        for account_id, row in moves.items():
            account = accounts[account_id]
            rid = account.code
            while len(rid) > 0:
                if not rid in account_result:
                    account_result[rid] = {
                        'debit': 0.0,
                        'credit': 0.0,
                        'balance': 0.0,
                    }

                account_result[rid]['debit'] += row.get('debit')
                account_result[rid]['credit'] += row.get('credit')
                account_result[rid]['balance'] += row.get('balance')
                account_result[rid]['name'] = accounts[account_id].name
                account_result[rid]['account_id'] = account_id
                account_result[rid]['code'] = rid
                rid = rid[:-2]

        return account_result

    def _fetch_moves_by_account_id_and_partner_id(self, accounts, default_partner_id):
        account_result = {}
        indexes = {}
        (tables, where_clause, where_params, wheres) = self._prepare_sql()
        filters = " AND ".join(wheres)
................................................................................
            if not rid in account_result:
                account_result[rid] = []
            account_result[rid].append(row)
            assert key not in indexes or (key in indexes and indexes[key] == 0 )
            indexes[key] = len(account_result[rid]) - 1
        
        return (account_result, indexes)


    def _get_accounts_by_code(self, used_context, accounts, display_account):
        results = self._fetch_moves_by_account_code(accounts)
        date_to = dateutil.parser.parse(used_context['date_from']) - timedelta(days=1)
        used_context_previous = copy.copy(used_context)
        used_context_previous.update({'date_to': date_to, 'date_from': False})
        account_result_previous = self.with_context(used_context_previous)._fetch_moves_by_account_code(accounts)

        res = []
        codes = results.keys() + account_result_previous.keys()
        def sort_by_code(x, y):
            a = x.ljust(6, '0')
            b = y.ljust(6, '0')
            if len(x) > 6:
                a = x[:6]
            if len(y) > 6:
                b = y[:6]
            return int(a) - int(b)
        
        codes = sorted(codes, cmp=sort_by_code)
        for code in codes:
            
            result = {
                'debit': 0.0,
                'credit': 0.0,
                'code': None,
                'name': None
            }
            result['type'] = 'line'
            result.update(results.get(code, {}))
            result['balance_prev'] = 0.0
            result['balance_total'] = 0.0
            if code in account_result_previous:
                result['balance_prev'] = account_result_previous[code]['balance']
                result['code'] = account_result_previous[code]['code']
                result['name'] = account_result_previous[code]['name']
            res.append(result)

        return res

    #tomado de: account/report/account_balance.py
    def _get_accounts(self, used_context, accounts, display_account, default_partner_id):
        """ compute the balance, debit and credit for the provided accounts
            :Arguments:
                `accounts`: list of accounts record,
                `display_account`: it's used to display either all accounts or those accounts which balance is > 0
                `default_partner_id': partner for unknown
            :Returns a list of dictionary of Accounts with following key and value
                `name`: Account name,
                `code`: Account code,
                `credit`: total amount of credit,
                `debit`: total amount of debit,
                `balance`: total amount of balance,
                `type`: `line` or `subline` or `subtotal`
        """

            
        account_result = self._fetch_moves_by_account_id(accounts)
        (account_partner_result, _) = self._fetch_moves_by_account_id_and_partner_id(accounts, default_partner_id)

        date_to = dateutil.parser.parse(used_context['date_from']) - timedelta(days=1)
        used_context_previous = copy.copy(used_context)
        used_context_previous.update({'date_to': date_to, 'date_from': False})
        account_result_previous = self.with_context(used_context_previous)._fetch_moves_by_account_id(accounts)
        (account_partner_result_previous, account_partner_result_previous_idx) = self.with_context(used_context_previous)._fetch_moves_by_account_id_and_partner_id(accounts, default_partner_id)

        #query all partners
        partners = {}
        for partner in self.env['res.partner'].search([]):
            partners[partner.id] = partner

        def get_partners(account_id):
            vlist = []
            if account_id in account_partner_result.keys():
                    for account_partner in account_partner_result[account_id]:
                        res_partner = dict((fn, 0.0) for fn in ['balance_prev', 'credit', 'debit', 'balance', 'balance_total'])
                        partner_id = account_partner.get('partner_id')
                        if partner_id not in partners:
                            partner_id = default_partner_id
                        
                        if partner_id not in partners:
                            raise UserError(_('Asociado en Elementos de diaro con id %s no ubicado en Asociados, indique un partner por defecto') % (str(partner_id)))
................................................................................
                        res_partner['type'] = 'subline'
                        res_partner['code'] = partners[partner_id].vat
                        res_partner['name'] = partners[partner_id].name
                        res_partner['debit'] = account_partner.get('debit')
                        res_partner['credit'] = account_partner.get('credit')
                        res_partner['balance'] = account_partner.get('balance')
                        res_partner['balance_total'] = res_partner['balance']

                        key = '%d.%d' % (account_id, partner_id)
                            
                        if account_id in account_partner_result_previous and key in account_partner_result_previous_idx:
                            previous = account_partner_result_previous[account_id][account_partner_result_previous_idx[key]]
                            res_partner['balance_prev'] = previous['balance']
                            res_partner['balance_total'] = previous['balance'] + res_partner['balance']
                            
                        vlist.append(res_partner)
            return vlist
................................................................................
        if not data.get('form') or not self.env.context.get('active_model'):
            raise UserError(_("Form content is missing, this report cannot be printed."))

        self.model = self.env.context.get('active_model')
        docs = self.env[self.model].browse(self.env.context.get('active_ids', []))
        display_account = data['form'].get('display_account')
        default_partner = data['form'].get('default_unknown_partner_id')
        group_by = data['form'].get('group_by')
        accounts = docs if self.model == 'account.account' else self.env['account.account'].search([])
        if group_by == 'partner':
            account_res = self.with_context(data['form'].get('used_context'))\
                              ._get_accounts(data['form'].get('used_context'), accounts, display_account, default_partner)
        elif group_by == 'code':
            account_res = self.with_context(data['form'].get('used_context'))\
                              ._get_accounts_by_code(data['form'].get('used_context'), accounts, display_account)
        else:
            raise RuntimeError('unknown group_by %s' %(group_by))

        docargs = {
            'doc_ids': self.ids,
            'doc_model': self.model,
            'data': data['form'],
            'docs': docs,
            'time': time,
            'Accounts': account_res,
        }

        return self.env['report'].render('trial_balance_co.report_partner_trial_balance', docargs)

Changes to trial_balance_co/wizard/report_partner_trial_balance.py.

7
8
9
10
11
12
13




14
15
16
17
18

19
20
21
22
23
24
    _description = 'Partner Trial Balance Report'

    date_from = fields.Date(string='Start Date', required=True)
    #TODO se sobreescribe relacion
    #por tamano en base de datos
    journal_ids = fields.Many2many('account.journal', 'trial_balance_co_reportptr_journal_rel', 'account_id', 'journal_id', string='Journals', required=True)
    default_unknown_partner = fields.Many2one('res.partner', string='Default Unknown Partner', required=True)




    
    def _print_report(self, data):
        data = self.pre_print_report(data)
        data['form'].update({
            'default_unknown_partner_id': self.default_unknown_partner.id

        })
        records = self.env[data['model']].browse(data.get('ids', []))
        action = self.env['report'].get_action(records, 'trial_balance_co.report_partner_trial_balance', data=data)
        return action









>
>
>
>
|



|
>






7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    _description = 'Partner Trial Balance Report'

    date_from = fields.Date(string='Start Date', required=True)
    #TODO se sobreescribe relacion
    #por tamano en base de datos
    journal_ids = fields.Many2many('account.journal', 'trial_balance_co_reportptr_journal_rel', 'account_id', 'journal_id', string='Journals', required=True)
    default_unknown_partner = fields.Many2one('res.partner', string='Default Unknown Partner', required=True)
    group_by = fields.Selection([
        ('partner', 'Partner'),
        ('code', 'Account Code')
    ], string='Group By', required=True)

    def _print_report(self, data):
        data = self.pre_print_report(data)
        data['form'].update({
            'default_unknown_partner_id': self.default_unknown_partner.id,
            'group_by': self.group_by
        })
        records = self.env[data['model']].browse(data.get('ids', []))
        action = self.env['report'].get_action(records, 'trial_balance_co.report_partner_trial_balance', data=data)
        return action


Changes to trial_balance_co/wizard/report_partner_trial_balance_view.xml.

7
8
9
10
11
12
13

14
15
16
17
18
19
20
        <field name="model">trial_balance_co.report.partner_trial_balance</field>
        <field name="inherit_id" ref="account.account_common_report_view"/>
        <field name="arch" type="xml">
          <data>
            <xpath expr="//field[@name='target_move']" position="after">
              <field name="display_account" widget="radio"/>
              <field name="default_unknown_partner" />

              <newline/>
            </xpath>
          </data>
        </field>
    </record>

    <record id="action_account_balance_menu" model="ir.actions.act_window">







>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
        <field name="model">trial_balance_co.report.partner_trial_balance</field>
        <field name="inherit_id" ref="account.account_common_report_view"/>
        <field name="arch" type="xml">
          <data>
            <xpath expr="//field[@name='target_move']" position="after">
              <field name="display_account" widget="radio"/>
              <field name="default_unknown_partner" />
              <field name="group_by" />
              <newline/>
            </xpath>
          </data>
        </field>
    </record>

    <record id="action_account_balance_menu" model="ir.actions.act_window">