This file is indexed.

/usr/lib/python2.7/dist-packages/trytond/modules/account_fr/account.py is in tryton-modules-account-fr 3.8.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  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
 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
 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
262
263
264
265
266
267
268
269
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import csv
from io import BytesIO

from sql import Table

from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
from trytond.wizard import Wizard, StateView, StateTransition, Button
from trytond.model import ModelView, fields


__all__ = ['TaxTemplate', 'TaxRuleTemplate',
    'AccountFrFEC', 'AccountFrFECStart', 'AccountFrFECResult']
__metaclass__ = PoolMeta


class TaxTemplate:
    __name__ = 'account.tax.template'

    @classmethod
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        model_data = Table('ir_model_data')

        # Migration from 3.0: new tax rates
        if module_name == 'account_fr':
            for old_id, new_id in (
                    ('tva_vente_19_6', 'tva_vente_taux_normal'),
                    ('tva_vente_7', 'tva_vente_taux_intermediaire'),
                    ('tva_vente_intracommunautaire_19_6',
                        'tva_vente_intracommunautaire_taux_normal'),
                    ('tva_vente_intracommunautaire_7',
                        'tva_vente_intracommunautaire_taux_intermediaire'),
                    ('tva_achat_19_6', 'tva_achat_taux_normal'),
                    ('tva_achat_7', 'tva_achat_taux_intermediaire'),
                    ('tva_achat_intracommunautaire_19_6',
                        'tva_achat_intracommunautaire_taux_normal'),
                    ):
                cursor.execute(*model_data.select(model_data.id,
                        where=(model_data.fs_id == new_id)
                        & (model_data.module == module_name)))
                if cursor.fetchone():
                    continue
                cursor.execute(*model_data.update(
                        columns=[model_data.fs_id],
                        values=[new_id],
                        where=(model_data.fs_id == old_id)
                        & (model_data.module == module_name)))

        super(TaxTemplate, cls).__register__(module_name)


class TaxRuleTemplate:
    __name__ = 'account.tax.rule.template'

    @classmethod
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        model_data = Table('ir_model_data')

        if module_name == 'account_fr':
            for old_id, new_id in (
                    ('tax_rule_ventes_intracommunautaires_19_6',
                        'tax_rule_ventes_intracommunautaires_taux_normal'),
                    ('tax_rule_ventes_intracommunautaires_7',
                        'tax_rule_ventes_intracommunautaires_taux_intermediaire'),
                    ):
                cursor.execute(*model_data.update(
                        columns=[model_data.fs_id],
                        values=[new_id],
                        where=(model_data.fs_id == old_id)
                        & (model_data.module == module_name)))

        super(TaxRuleTemplate, cls).__register__(module_name)


class AccountFrFEC(Wizard):
    'Generate FEC'
    __name__ = 'account.fr.fec'

    start = StateView('account.fr.fec.start',
        'account_fr.fec_start_view_form', [
            Button('Cancel', 'end', 'tryton-cancel'),
            Button('Generate', 'generate', 'tryton-ok', default=True),
            ])
    generate = StateTransition()
    result = StateView('account.fr.fec.result',
        'account_fr.fec_result_view_form', [
            Button('Close', 'end', 'tryton-close'),
            ])

    def transition_generate(self):
        fec = BytesIO()
        writer = self.get_writer(fec)
        format_date = self.get_format_date()
        format_number = self.get_format_number()
        for row in self.get_start_balance():
            writer.writerow([(c or '').encode('utf-8') for c in row])
        for line in self.get_lines():
            row = self.get_row(line, format_date, format_number)
            writer.writerow([(c or '').encode('utf-8') for c in row])
        self.result.file = fec.getvalue()
        return 'result'

    def default_result(self, fields):
        file_ = self.result.file
        self.result.file = None  # No need to store it in session
        format_date = self.get_format_date()
        filename = '%sFEC%s.csv' % (
            self.start.fiscalyear.company.party.siren or '',
            format_date(self.start.fiscalyear.end_date),
            )
        return {
            'file': file_,
            'filename': filename,
            }

    def get_writer(self, fd):
        return csv.writer(fd)

    def get_format_date(self):
        pool = Pool()
        Lang = pool.get('ir.lang')
        fr, = Lang.search([('code', '=', 'fr_FR')])
        return lambda value: Lang.strftime(value, fr.code, '%Y%m%d')

    def get_format_number(self):
        pool = Pool()
        Lang = pool.get('ir.lang')
        fr, = Lang.search([('code', '=', 'fr_FR')])
        return lambda value: Lang.format(fr, '%.2f', value)

    def get_start_balance(self):
        pool = Pool()
        Account = pool.get('account.account')
        format_date = self.get_format_date()
        format_number = self.get_format_number()

        with Transaction().set_context(
                periods=[-1],
                fiscalyear=self.start.fiscalyear.id,
                posted=True,
                cumulate=True):
            accounts = Account.search([])

        for account in accounts:
            if not account.credit and not account.debit:
                continue
            yield [
                self.start.deferral_journal.code,
                self.start.deferral_journal.name,
                self.start.deferral_post_number,
                format_date(self.start.fiscalyear.start_date),
                account.code,
                account.name,
                '',
                '',
                '',
                format_date(self.start.fiscalyear.start_date),
                '',
                format_number(account.debit or 0),
                format_number(account.credit or 0),
                '',
                '',
                format_date(self.start.fiscalyear.start_date),
                '',
                '',
                ]

    def get_lines(self):
        pool = Pool()
        Line = pool.get('account.move.line')

        return Line.search([
                ('move.period.fiscalyear', '=', self.start.fiscalyear.id),
                ('move.state', '=', 'posted'),
                ],
            order=[
                ('move.post_number', 'ASC'),
                ])

    def get_row(self, line, format_date, format_number):
        def description():
            value = line.move.description or ''
            if line.description:
                if value:
                    value += ' - '
                value += line.description
            return value
        return [
            line.move.journal.code,
            line.move.journal.name,
            line.move.post_number,
            format_date(line.move.date),
            line.account.code,
            line.account.name,
            line.party.code if line.party else '',
            line.party.name if line.party else '',
            self.get_reference(line),
            format_date(self.get_reference_date(line)),
            description(),
            format_number(line.debit or 0),
            format_number(line.credit or 0),
            line.reconciliation.rec_name if line.reconciliation else '',
            format_date(line.reconciliation.create_date)
            if line.reconciliation else '',
            format_date(line.move.post_date),
            format_number(line.amount_second_currency)
            if line.amount_second_currency else '',
            line.second_currency.code if line.amount_second_currency else '',
            ]

    def get_reference(self, line):
        pool = Pool()
        try:
            Invoice = pool.get('account.invoice')
        except KeyError:
            Invoice = None
        if not line.move.origin:
            return ''
        if Invoice and isinstance(line.move.origin, Invoice):
            return line.move.origin.number
        return line.move.origin.rec_name

    def get_reference_date(self, line):
        pool = Pool()
        try:
            Invoice = pool.get('account.invoice')
        except KeyError:
            Invoice = None
        if Invoice and isinstance(line.move.origin, Invoice):
            return line.move.origin.invoice_date
        return line.move.post_date


class AccountFrFECStart(ModelView):
    'Generate FEC'
    __name__ = 'account.fr.fec.start'

    fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
        required=True, domain=[
            ('state', '=', 'close'),
            ])
    type = fields.Selection([
            ('is-bic', 'IS-BIC'),
            ], 'Type', required=True)
    deferral_journal = fields.Many2One('account.journal',
        'Deferral Journal', required=True,
        help='Journal used for pseudo deferral move')
    deferral_post_number = fields.Char('Deferral Number', required=True,
        help='Post number used for pseudo deferral move')

    @classmethod
    def default_type(cls):
        return 'is-bic'

    @classmethod
    def default_deferral_post_number(cls):
        return '0'


class AccountFrFECResult(ModelView):
    'Generate FEC'
    __name__ = 'account.fr.fec.result'

    file = fields.Binary('File', readonly=True, filename='filename')
    filename = fields.Char('File Name', readonly=True)