odoo10_addons

Check-in [56c723e76c]

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

Overview
Comment:trial_balance_co: se adiciona cuenta desconocida, ya que pueden haber movimientos sin realiacion a account.account
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | enterprise
Files: files | file ages | folders
SHA3-256: 56c723e76c1e605e664d22e9323b5d2cf678c19c5c8ddb0becb9b5cd89874230
User & Date: bit4bit 2019-03-09 23:53:45
Context
2019-03-10
00:21
corr check-in: de8dd9a7a4 user: bit4bit tags: enterprise
2019-03-09
23:53
trial_balance_co: se adiciona cuenta desconocida, ya que pueden haber movimientos sin realiacion a account.account check-in: 56c723e76c user: bit4bit tags: enterprise
23:21
se muestra desde clase en trial_balance_co check-in: 6ed9313c1c user: bit4bit tags: enterprise
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to trial_balance_co/report/balance.py.

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
..
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
        params = (tuple(accounts.ids),) + tuple(where_params)
        self.env.cr.execute(request, params)
        for row in self.env.cr.dictfetchall():
            account_result[int(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_by_code = self.env['account.account'].search([('code', '=', rid)])

                account_result[rid]['debit'] += row.get('debit')
                account_result[rid]['credit'] += row.get('credit')
                account_result[rid]['balance'] += row.get('balance')
                if account_by_code:
                    account_result[rid]['name'] = account_by_code.name
                else:
                    account_result[rid]['name'] = accounts[account_id].name
                account_result[rid]['account_id'] = account_id
                account_result[rid]['code'] = rid
                if len(rid) > 2:
                    rid = rid[:-2]
................................................................................
            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:
................................................................................
        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)







|



|
>
>
>







 







|







 







|
|



|







 







>







|













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
72
..
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
        params = (tuple(accounts.ids),) + tuple(where_params)
        self.env.cr.execute(request, params)
        for row in self.env.cr.dictfetchall():
            account_result[int(row.pop('id'))] = row

        return account_result

    def _fetch_moves_by_account_code(self, accounts, default_unknown_account_id):
        account_result = collections.OrderedDict()
        moves = self._fetch_moves_by_account_id(accounts)
        for account_id, row in moves.items():
            account = self.env['account.account'].browse(account_id)
            if not account.exists():
                account = self.env['account.account'].browse(default_unknown_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_by_code = self.env['account.account'].search([('code', '=', rid)])

                account_result[rid]['debit'] += row.get('debit')
                account_result[rid]['credit'] += row.get('credit')
                account_result[rid]['balance'] += row.get('balance')
                if account_by_code.exists():
                    account_result[rid]['name'] = account_by_code.name
                else:
                    account_result[rid]['name'] = accounts[account_id].name
                account_result[rid]['account_id'] = account_id
                account_result[rid]['code'] = rid
                if len(rid) > 2:
                    rid = rid[:-2]
................................................................................
            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, default_account_id):
        results = self._fetch_moves_by_account_code(accounts, default_account_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_code(accounts, default_account_id)

        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:
................................................................................
        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')
        default_account = data['form'].get('default_unknown_account_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, default_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
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









>
>









>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    _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)
    default_unknown_account = fields.Many2one('account.account', string='Default Unknown Account', 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,
            'default_unknown_account_id': self.default_unknown_account.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" />

              <field name="group_by" />
              <newline/>
            </xpath>
          </data>
        </field>
    </record>








>







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="default_unknown_account" />
              <field name="group_by" />
              <newline/>
            </xpath>
          </data>
        </field>
    </record>