formatting, line: test for delete of party
This commit is contained in:
parent
78f160bf0b
commit
619a17bcd6
16 changed files with 701 additions and 516 deletions
|
@ -4,15 +4,12 @@
|
|||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.model import Workflow, ModelView, ModelSQL, fields
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import Eval, If, Or, Bool
|
||||
from trytond.pyson import Eval, If, Or
|
||||
from trytond.pool import Pool
|
||||
from trytond.report import Report
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from decimal import Decimal
|
||||
from sql.operators import Equal, Between
|
||||
from sql import Literal, Null
|
||||
from datetime import timedelta
|
||||
from .book import sel_state_book
|
||||
|
||||
|
@ -29,21 +26,25 @@ STATES = {
|
|||
Eval('state_cashbook', '') != 'open',
|
||||
),
|
||||
}
|
||||
DEPENDS=['state', 'state_cashbook']
|
||||
DEPENDS = ['state', 'state_cashbook']
|
||||
|
||||
|
||||
class Reconciliation(Workflow, ModelSQL, ModelView):
|
||||
'Cashbook Reconciliation'
|
||||
__name__ = 'cashbook.recon'
|
||||
|
||||
cashbook = fields.Many2One(string='Cashbook', required=True, select=True,
|
||||
cashbook = fields.Many2One(
|
||||
string='Cashbook', required=True, select=True,
|
||||
model_name='cashbook.book', ondelete='CASCADE', readonly=True)
|
||||
date = fields.Date(string='Date', required=True, select=True,
|
||||
date = fields.Date(
|
||||
string='Date', required=True, select=True,
|
||||
states=STATES, depends=DEPENDS)
|
||||
feature = fields.Function(fields.Char(string='Feature', readonly=True,
|
||||
feature = fields.Function(fields.Char(
|
||||
string='Feature', readonly=True,
|
||||
states={'invisible': True}), 'on_change_with_feature')
|
||||
|
||||
date_from = fields.Date(string='Start Date',
|
||||
date_from = fields.Date(
|
||||
string='Start Date',
|
||||
required=True,
|
||||
domain=[
|
||||
If(Eval('date_to') & Eval('date_from'),
|
||||
|
@ -51,7 +52,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
()),
|
||||
],
|
||||
states=STATES, depends=DEPENDS+['date_to'])
|
||||
date_to = fields.Date(string='End Date',
|
||||
date_to = fields.Date(
|
||||
string='End Date',
|
||||
required=True, select=True,
|
||||
domain=[
|
||||
If(Eval('date_to') & Eval('date_from'),
|
||||
|
@ -59,14 +61,17 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
()),
|
||||
],
|
||||
states=STATES, depends=DEPENDS+['date_from'])
|
||||
start_amount = fields.Numeric(string='Start Amount', required=True,
|
||||
start_amount = fields.Numeric(
|
||||
string='Start Amount', required=True,
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
depends=['currency_digits'])
|
||||
end_amount = fields.Numeric(string='End Amount', required=True,
|
||||
end_amount = fields.Numeric(
|
||||
string='End Amount', required=True,
|
||||
readonly=True, digits=(16, Eval('currency_digits', 2)),
|
||||
depends=['currency_digits'])
|
||||
|
||||
lines = fields.One2Many(string='Lines', field='reconciliation',
|
||||
lines = fields.One2Many(
|
||||
string='Lines', field='reconciliation',
|
||||
model_name='cashbook.line', states=STATES,
|
||||
depends=DEPENDS+['date_from', 'date_to', 'cashbook'],
|
||||
add_remove=[
|
||||
|
@ -80,18 +85,23 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
('date', '<=', Eval('date_to')),
|
||||
])
|
||||
|
||||
currency = fields.Function(fields.Many2One(model_name='currency.currency',
|
||||
currency = fields.Function(fields.Many2One(
|
||||
model_name='currency.currency',
|
||||
string="Currency"), 'on_change_with_currency')
|
||||
currency_digits = fields.Function(fields.Integer(string='Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
predecessor = fields.Function(fields.Many2One(string='Predecessor', readonly=True,
|
||||
currency_digits = fields.Function(fields.Integer(
|
||||
string='Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
predecessor = fields.Function(fields.Many2One(
|
||||
string='Predecessor', readonly=True,
|
||||
model_name='cashbook.recon'),
|
||||
'on_change_with_predecessor')
|
||||
|
||||
state = fields.Selection(string='State', required=True, readonly=True,
|
||||
state = fields.Selection(
|
||||
string='State', required=True, readonly=True,
|
||||
select=True, selection=sel_reconstate)
|
||||
state_string = state.translated('state')
|
||||
state_cashbook = fields.Function(fields.Selection(string='State of Cashbook',
|
||||
state_cashbook = fields.Function(fields.Selection(
|
||||
string='State of Cashbook',
|
||||
readonly=True, states={'invisible': True}, selection=sel_state_book),
|
||||
'on_change_with_state_cashbook')
|
||||
|
||||
|
@ -140,9 +150,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
[ # enclose other record
|
||||
('date_from', '>=', self.date_from),
|
||||
('date_to', '<=', self.date_to),
|
||||
],
|
||||
],
|
||||
]
|
||||
]]]
|
||||
|
||||
if Recon.search_count(query) > 0:
|
||||
raise UserError(gettext('cashbook.msg_recon_err_overlap'))
|
||||
|
@ -155,18 +163,17 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
for reconciliation in reconciliations:
|
||||
if Line.search_count([
|
||||
('date', '>', reconciliation.date_from),
|
||||
('date', '<', reconciliation.date_to),
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('state', 'not in', ['check', 'recon']),
|
||||
]) > 0:
|
||||
('date', '>', reconciliation.date_from),
|
||||
('date', '<', reconciliation.date_to),
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('state', 'not in', ['check', 'recon']),
|
||||
]) > 0:
|
||||
raise UserError(gettext(
|
||||
'cashbook.mds_recon_deny_line_not_check',
|
||||
bookname = reconciliation.cashbook.rec_name,
|
||||
reconame = reconciliation.rec_name,
|
||||
datefrom = Report.format_date(reconciliation.date_from),
|
||||
dateto = Report.format_date(reconciliation.date_to),
|
||||
))
|
||||
bookname=reconciliation.cashbook.rec_name,
|
||||
reconame=reconciliation.rec_name,
|
||||
datefrom=Report.format_date(reconciliation.date_from),
|
||||
dateto=Report.format_date(reconciliation.date_to)))
|
||||
|
||||
@classmethod
|
||||
def get_values_wfedit(cls, reconciliation):
|
||||
|
@ -191,7 +198,7 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
values = {}
|
||||
if reconciliation.predecessor:
|
||||
values['start_amount'] = reconciliation.predecessor.end_amount
|
||||
else :
|
||||
else:
|
||||
values['start_amount'] = Decimal('0.0')
|
||||
values['end_amount'] = values['start_amount']
|
||||
|
||||
|
@ -209,7 +216,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
# add amounts of new lines
|
||||
values['end_amount'] += sum([x.credit - x.debit for x in lines])
|
||||
# add amounts of already linked lines
|
||||
values['end_amount'] += sum([x.credit - x.debit for x in reconciliation.lines])
|
||||
values['end_amount'] += sum([
|
||||
x.credit - x.debit for x in reconciliation.lines])
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
|
@ -248,18 +256,18 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if reconciliation.predecessor.state != 'done':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_predecessor_not_done',
|
||||
recname_p = reconciliation.predecessor.rec_name,
|
||||
recname_c = reconciliation.rec_name,
|
||||
))
|
||||
recname_p=reconciliation.predecessor.rec_name,
|
||||
recname_c=reconciliation.rec_name))
|
||||
|
||||
# check if current.date_from == predecessor.date_to
|
||||
if reconciliation.predecessor.date_to != reconciliation.date_from:
|
||||
if reconciliation.predecessor.date_to != \
|
||||
reconciliation.date_from:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_date_from_to_mismatch',
|
||||
datefrom = Report.format_date(reconciliation.date_from),
|
||||
dateto = Report.format_date(reconciliation.predecessor.date_to),
|
||||
recname = reconciliation.rec_name,
|
||||
))
|
||||
datefrom=Report.format_date(reconciliation.date_from),
|
||||
dateto=Report.format_date(
|
||||
reconciliation.predecessor.date_to),
|
||||
recname=reconciliation.rec_name))
|
||||
|
||||
to_write.extend([
|
||||
[reconciliation],
|
||||
|
@ -281,13 +289,11 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
to_wfrecon_line = []
|
||||
for reconciliation in reconciliations:
|
||||
to_wfrecon_line.extend([
|
||||
x for x in reconciliation.lines \
|
||||
if x.state == 'check'
|
||||
])
|
||||
x for x in reconciliation.lines
|
||||
if x.state == 'check'])
|
||||
to_wfdone_line.extend([
|
||||
x for x in reconciliation.lines \
|
||||
if x.state == 'recon'
|
||||
])
|
||||
x for x in reconciliation.lines
|
||||
if x.state == 'recon'])
|
||||
|
||||
# deny if there are lines not linked to reconciliation
|
||||
if Line.search_count([
|
||||
|
@ -299,14 +305,12 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
('date', '<', reconciliation.date_to),
|
||||
],
|
||||
# lines at from-date must relate to a reconciliation
|
||||
('date', '=', reconciliation.date_from),
|
||||
],
|
||||
]) > 0:
|
||||
('date', '=', reconciliation.date_from)],
|
||||
]) > 0:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_lines_no_linked',
|
||||
date_from = Report.format_date(reconciliation.date_from),
|
||||
date_to = Report.format_date(reconciliation.date_to),
|
||||
))
|
||||
date_from=Report.format_date(reconciliation.date_from),
|
||||
date_to=Report.format_date(reconciliation.date_to),))
|
||||
|
||||
if len(to_wfrecon_line) > 0:
|
||||
Line.wfrecon(to_wfrecon_line)
|
||||
|
@ -318,9 +322,12 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
""" short + name
|
||||
"""
|
||||
return '%(from)s - %(to)s | %(start_amount)s %(symbol)s - %(end_amount)s %(symbol)s [%(num)s]' % {
|
||||
'from': Report.format_date(self.date_from, None) if self.date_from is not None else '-',
|
||||
'to': Report.format_date(self.date_to, None) if self.date_to is not None else '-',
|
||||
'start_amount': Report.format_number(self.start_amount or 0.0, None),
|
||||
'from': Report.format_date(self.date_from, None)
|
||||
if self.date_from is not None else '-',
|
||||
'to': Report.format_date(self.date_to, None)
|
||||
if self.date_to is not None else '-',
|
||||
'start_amount': Report.format_number(
|
||||
self.start_amount or 0.0, None),
|
||||
'end_amount': Report.format_number(self.end_amount or 0.0, None),
|
||||
'symbol': getattr(self.currency, 'symbol', '-'),
|
||||
'num': len(self.lines),
|
||||
|
@ -459,9 +466,8 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if reconciliation.cashbook.state != 'open':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_book_deny_write',
|
||||
bookname = reconciliation.cashbook.rec_name,
|
||||
state_txt = reconciliation.cashbook.state_string,
|
||||
))
|
||||
bookname=reconciliation.cashbook.rec_name,
|
||||
state_txt=reconciliation.cashbook.state_string))
|
||||
super(Reconciliation, cls).write(*args)
|
||||
|
||||
@classmethod
|
||||
|
@ -472,16 +478,14 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if reconciliation.cashbook.state == 'closed':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_line_deny_delete1',
|
||||
linetxt = reconciliation.rec_name,
|
||||
bookname = reconciliation.cashbook.rec_name,
|
||||
bookstate = reconciliation.cashbook.state_string,
|
||||
))
|
||||
linetxt=reconciliation.rec_name,
|
||||
bookname=reconciliation.cashbook.rec_name,
|
||||
bookstate=reconciliation.cashbook.state_string))
|
||||
if reconciliation.state != 'edit':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_deny_delete2',
|
||||
recontxt = reconciliation.rec_name,
|
||||
reconstate = reconciliation.state_string,
|
||||
))
|
||||
recontxt=reconciliation.rec_name,
|
||||
reconstate=reconciliation.state_string))
|
||||
|
||||
super(Reconciliation, cls).delete(reconciliations)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue