odoo10_addons

Check-in [5e97f65283]

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

Overview
Comment:anexo_al_balance: se permite indicar un tercero para ser usado cuando un movimiento a perdido la referencia al tercero
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | enterprise
Files: files | file ages | folders
SHA3-256: 5e97f6528302210736b811557d6d52ea91dc12dc31f666e3eb21a8c9632f9e68
User & Date: bit4bit 2019-02-14 13:23:27
Context
2019-02-14
13:24
se agregan archivos de licensia para AGPL check-in: 82c8bc311d user: bit4bit tags: enterprise
13:23
anexo_al_balance: se permite indicar un tercero para ser usado cuando un movimiento a perdido la referencia al tercero check-in: 5e97f65283 user: bit4bit tags: enterprise
2018-12-07
17:48
se mueve menu "Partner Trial Balance" a account.menu_finance_reports ya que enterprise no tiene account.menu_finance_legal_statement" check-in: 4afd03dfff user: bit4bit tags: enterprise
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to anexo_al_balance/report/balance.py.

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
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
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
                   " 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):
        account_result = {}
        indexes = {}
        (tables, where_clause, where_params, wheres) = self._prepare_sql()
        filters = " AND ".join(wheres)
        # compute the balance, debit and credit for the provided accounts
        request = ("SELECT account_id AS id, account_move_line.partner_id as partner_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,account_move_line.partner_id")
        params = (tuple(accounts.ids),) + tuple(where_params)
        self.env.cr.execute(request, params)

        for row in self.env.cr.dictfetchall():
            rid = row.pop('id')

            key = '%d.%d' % (rid, row.get('partner_id'))
            if not rid in account_result:
                account_result[rid] = []
            account_result[rid].append(row)
            assert not key in indexes
            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):
        """ 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)
        
        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)
        
        #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')





                        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 key in account_partner_result_previous_idx:
                            previous = account_partner_result[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
            
        account_res = []
................................................................................
            res['name'] = account.name
            res['type'] = 'line'
            
            if account.id in account_result.keys():
                res['debit'] = account_result[account.id].get('debit')
                res['credit'] = account_result[account.id].get('credit')
                res['balance'] = account_result[account.id].get('balance')
                
            if account.id in account_result_previous.keys() and account.id in account_result.keys():
                res['balance_prev'] = account_result_previous[account.id].get('balance')
                res['balance_total'] = res['balance_prev'] + res['balance']
            elif account.id in account_result_previous.keys():
                res['debit'] = account_result_previous[account.id].get('debit')
                res['credit'] = account_result_previous[account.id].get('credit')
                res['balance'] = account_result_previous[account.id].get('balance')
................................................................................
    def render_html(self, docids, data=None):
        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')

        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)

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

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







|









>


>
|









|







 







|





|
<











>
>
>
>
>







|
<

|
|







 







<







 







>

|











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
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
119
120
...
125
126
127
128
129
130
131

132
133
134
135
136
137
138
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
                   " 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)
        # compute the balance, debit and credit for the provided accounts
        request = ("SELECT account_id AS id, account_move_line.partner_id as partner_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,account_move_line.partner_id")
        params = (tuple(accounts.ids),) + tuple(where_params)
        self.env.cr.execute(request, params)
        
        for row in self.env.cr.dictfetchall():
            rid = row.pop('id')
            partner_id = row.get('partner_id') or default_partner_id
            key = '%d.%d' % (rid, partner_id)
            if not rid in account_result:
                account_result[rid] = []
            account_result[rid].append(row)
            assert not key in indexes
            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
            
        account_res = []
................................................................................
            res['name'] = account.name
            res['type'] = 'line'
            
            if account.id in account_result.keys():
                res['debit'] = account_result[account.id].get('debit')
                res['credit'] = account_result[account.id].get('credit')
                res['balance'] = account_result[account.id].get('balance')

            if account.id in account_result_previous.keys() and account.id in account_result.keys():
                res['balance_prev'] = account_result_previous[account.id].get('balance')
                res['balance_total'] = res['balance_prev'] + res['balance']
            elif account.id in account_result_previous.keys():
                res['debit'] = account_result_previous[account.id].get('debit')
                res['credit'] = account_result_previous[account.id].get('credit')
                res['balance'] = account_result_previous[account.id].get('balance')
................................................................................
    def render_html(self, docids, data=None):
        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('anexo_al_balance.report_partner_trial_balance', docargs)

Changes to anexo_al_balance/wizard/report_partner_trial_balance.py.

6
7
8
9
10
11
12

13
14
15



16
17
18
19
20
    _name = 'anexo_al_balance.report.partner_trial_balance'
    _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', 'anexo_al_balance_reportptr_journal_rel', 'account_id', 'journal_id', string='Journals', required=True)

    
    def _print_report(self, data):
        data = self.pre_print_report(data)



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









>



>
>
>





6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    _name = 'anexo_al_balance.report.partner_trial_balance'
    _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', 'anexo_al_balance_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, 'anexo_al_balance.report_partner_trial_balance', data=data)
        return action


Changes to anexo_al_balance/wizard/report_partner_trial_balance_view.xml.

6
7
8
9
10
11
12

13
14
15
16
17
18
19
        <field name="name">Partner Trial Balance</field>
        <field name="model">anexo_al_balance.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"/>

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

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







>







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        <field name="name">Partner Trial Balance</field>
        <field name="model">anexo_al_balance.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">