/usr/lib/python2.7/dist-packages/trytond/modules/account_invoice/account.py is in tryton-modules-account-invoice 4.2.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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pyson import Eval
from trytond.pool import Pool, PoolMeta
__all__ = ['FiscalYear',
'Period', 'Move', 'Reconciliation']
class FiscalYear:
__metaclass__ = PoolMeta
__name__ = 'account.fiscalyear'
out_invoice_sequence = fields.Many2One('ir.sequence.strict',
'Customer Invoice Sequence', required=True,
domain=[
('code', '=', 'account.invoice'),
['OR',
('company', '=', Eval('company')),
('company', '=', None),
],
],
context={
'code': 'account.invoice',
'company': Eval('company'),
},
depends=['company'])
in_invoice_sequence = fields.Many2One('ir.sequence.strict',
'Supplier Invoice Sequence', required=True,
domain=[
('code', '=', 'account.invoice'),
['OR',
('company', '=', Eval('company')),
('company', '=', None),
],
],
context={
'code': 'account.invoice',
'company': Eval('company'),
},
depends=['company'])
out_credit_note_sequence = fields.Many2One('ir.sequence.strict',
'Customer Credit Note Sequence', required=True,
domain=[
('code', '=', 'account.invoice'),
['OR',
('company', '=', Eval('company')),
('company', '=', None),
],
],
context={
'code': 'account.invoice',
'company': Eval('company'),
}, depends=['company'])
in_credit_note_sequence = fields.Many2One('ir.sequence.strict',
'Supplier Credit Note Sequence', required=True,
domain=[
('code', '=', 'account.invoice'),
['OR',
('company', '=', Eval('company')),
('company', '=', None),
],
],
context={
'code': 'account.invoice',
'company': Eval('company'),
}, depends=['company'])
@classmethod
def __setup__(cls):
super(FiscalYear, cls).__setup__()
cls._error_messages.update({
'change_invoice_sequence': ('You can not change '
'invoice sequence in fiscal year "%s" because there are '
'already posted invoices in this fiscal year.'),
'different_invoice_sequence': ('Fiscal year "%(first)s" and '
'"%(second)s" have the same invoice sequence.'),
})
@classmethod
def validate(cls, years):
super(FiscalYear, cls).validate(years)
for year in years:
year.check_invoice_sequences()
def check_invoice_sequences(self):
for sequence in ('out_invoice_sequence', 'in_invoice_sequence',
'out_credit_note_sequence', 'in_credit_note_sequence'):
fiscalyears = self.search([
(sequence, '=', getattr(self, sequence).id),
('id', '!=', self.id),
])
if fiscalyears:
self.raise_user_error('different_invoice_sequence', {
'first': self.rec_name,
'second': fiscalyears[0].rec_name,
})
@classmethod
def write(cls, *args):
Invoice = Pool().get('account.invoice')
actions = iter(args)
for fiscalyears, values in zip(actions, actions):
for sequence in ('out_invoice_sequence', 'in_invoice_sequence',
'out_credit_note_sequence', 'in_credit_note_sequence'):
if not values.get(sequence):
continue
for fiscalyear in fiscalyears:
if (getattr(fiscalyear, sequence)
and (getattr(fiscalyear, sequence).id !=
values[sequence])):
if Invoice.search([
('invoice_date', '>=',
fiscalyear.start_date),
('invoice_date', '<=',
fiscalyear.end_date),
('number', '!=', None),
('type', '=', sequence[:-9]),
]):
cls.raise_user_error('change_invoice_sequence',
(fiscalyear.rec_name,))
super(FiscalYear, cls).write(*args)
class Period:
__metaclass__ = PoolMeta
__name__ = 'account.period'
out_invoice_sequence = fields.Many2One('ir.sequence.strict',
'Customer Invoice Sequence',
domain=[('code', '=', 'account.invoice')],
context={'code': 'account.invoice'},
states={
'invisible': Eval('type') != 'standard',
},
depends=['type'])
in_invoice_sequence = fields.Many2One('ir.sequence.strict',
'Supplier Invoice Sequence',
domain=[('code', '=', 'account.invoice')],
context={'code': 'account.invoice'},
states={
'invisible': Eval('type') != 'standard',
},
depends=['type'])
out_credit_note_sequence = fields.Many2One('ir.sequence.strict',
'Customer Credit Note Sequence',
domain=[('code', '=', 'account.invoice')],
context={'code': 'account.invoice'},
states={
'invisible': Eval('type') != 'standard',
},
depends=['type'])
in_credit_note_sequence = fields.Many2One('ir.sequence.strict',
'Supplier Credit Note Sequence',
domain=[('code', '=', 'account.invoice')],
context={'code': 'account.invoice'},
states={
'invisible': Eval('type') != 'standard',
},
depends=['type'])
@classmethod
def __setup__(cls):
super(Period, cls).__setup__()
cls._error_messages.update({
'change_invoice_sequence': ('You can not change the invoice '
'sequence in period "%s" because there is already an '
'invoice posted in this period'),
'different_invoice_sequence': ('Period "%(first)s" and '
'"%(second)s" have the same invoice sequence.'),
'different_period_fiscalyear_company': ('Period "%(period)s" '
'must have the same company as its fiscal year '
'(%(fiscalyear)s).'),
})
@classmethod
def validate(cls, periods):
super(Period, cls).validate(periods)
for period in periods:
period.check_invoice_sequences()
def check_invoice_sequences(self):
for sequence_name in ('out_invoice_sequence', 'in_invoice_sequence',
'out_credit_note_sequence', 'in_credit_note_sequence'):
sequence = getattr(self, sequence_name)
if not sequence:
continue
periods = self.search([
(sequence_name, '=', sequence.id),
('fiscalyear', '!=', self.fiscalyear.id),
])
if periods:
self.raise_user_error('different_invoice_sequence', {
'first': self.rec_name,
'second': periods[0].rec_name,
})
if (sequence.company
and sequence.company != self.fiscalyear.company):
self.raise_user_error('different_period_fiscalyear_company', {
'period': self.rec_name,
'fiscalyear': self.fiscalyear.rec_name,
})
@classmethod
def create(cls, vlist):
FiscalYear = Pool().get('account.fiscalyear')
vlist = [v.copy() for v in vlist]
for vals in vlist:
if vals.get('fiscalyear'):
fiscalyear = FiscalYear(vals['fiscalyear'])
for sequence in ('out_invoice_sequence', 'in_invoice_sequence',
'out_credit_note_sequence', 'in_credit_note_sequence'):
if not vals.get(sequence):
vals[sequence] = getattr(fiscalyear, sequence).id
return super(Period, cls).create(vlist)
@classmethod
def write(cls, *args):
Invoice = Pool().get('account.invoice')
actions = iter(args)
for periods, values in zip(actions, actions):
for sequence_name in ('out_invoice_sequence',
'in_invoice_sequence', 'out_credit_note_sequence',
'in_credit_note_sequence'):
if not values.get(sequence_name):
continue
for period in periods:
sequence = getattr(period, sequence_name)
if (sequence and sequence.id != values[sequence_name]):
if Invoice.search([
('invoice_date', '>=', period.start_date),
('invoice_date', '<=', period.end_date),
('number', '!=', None),
('type', '=', sequence_name[:-9]),
]):
cls.raise_user_error('change_invoice_sequence',
(period.rec_name,))
super(Period, cls).write(*args)
def get_invoice_sequence(self, invoice_type):
sequence = getattr(self, invoice_type + '_sequence')
if sequence:
return sequence
return getattr(self.fiscalyear, invoice_type + '_sequence')
class Move:
__metaclass__ = PoolMeta
__name__ = 'account.move'
@classmethod
def _get_origin(cls):
return super(Move, cls)._get_origin() + ['account.invoice']
class Reconciliation:
__metaclass__ = PoolMeta
__name__ = 'account.move.reconciliation'
@classmethod
def create(cls, vlist):
Invoice = Pool().get('account.invoice')
reconciliations = super(Reconciliation, cls).create(vlist)
move_ids = set()
account_ids = set()
for reconciliation in reconciliations:
move_ids |= {l.move.id for l in reconciliation.lines}
account_ids |= {l.account.id for l in reconciliation.lines}
invoices = Invoice.search([
('move', 'in', list(move_ids)),
('account', 'in', list(account_ids)),
])
Invoice.process(invoices)
return reconciliations
@classmethod
def delete(cls, reconciliations):
Invoice = Pool().get('account.invoice')
move_ids = set(l.move.id for r in reconciliations for l in r.lines)
invoices = Invoice.search([
('move', 'in', list(move_ids)),
])
super(Reconciliation, cls).delete(reconciliations)
Invoice.process(invoices)
|