Fix: Autopep8
This commit is contained in:
130
statement.py
130
statement.py
@@ -4,7 +4,8 @@
|
||||
from trytond.model import fields, ModelView
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Button, StateTransition, StateAction, StateView, Wizard
|
||||
from trytond.wizard import (
|
||||
Button, StateTransition, StateAction, StateView, Wizard)
|
||||
from decimal import Decimal
|
||||
from trytond.i18n import gettext
|
||||
from trytond.modules.currency.fields import Monetary
|
||||
@@ -52,7 +53,7 @@ class Statement(metaclass=PoolMeta):
|
||||
|
||||
query = statement.join(
|
||||
journal, condition=statement.journal == journal.id).join(
|
||||
device_journal,
|
||||
device_journal,
|
||||
condition=journal.id == device_journal.journal).join(
|
||||
device, condition=device_journal.device == device.id).join(
|
||||
user, condition=device.id == user.sale_device).select(
|
||||
@@ -121,6 +122,7 @@ class OpenStatementStart(ModelView):
|
||||
'Open Statement'
|
||||
__name__ = 'open.statement.start'
|
||||
|
||||
|
||||
class OpenStatementDone(ModelView):
|
||||
'Open Statement'
|
||||
__name__ = 'open.statement.done'
|
||||
@@ -145,7 +147,7 @@ class OpenStatement(Wizard):
|
||||
return {
|
||||
'result': self.result,
|
||||
}
|
||||
|
||||
|
||||
def transition_create_(self):
|
||||
pool = Pool()
|
||||
User = pool.get('res.user')
|
||||
@@ -172,7 +174,8 @@ class OpenStatement(Wizard):
|
||||
for journal in device.journals:
|
||||
if journal not in journals_of_draft_statements:
|
||||
values = {
|
||||
'name': '%s - %s' % (device.rec_name, journal.rec_name),
|
||||
'name': '%s - %s' % (
|
||||
device.rec_name, journal.rec_name),
|
||||
'journal': journal.id,
|
||||
'company': user.company.id,
|
||||
'start_balance': start_balances.get(journal.id,
|
||||
@@ -185,8 +188,10 @@ class OpenStatement(Wizard):
|
||||
results.append(gettext('sale_payment.open_statement',
|
||||
statement=journal.rec_name))
|
||||
else:
|
||||
results.append(gettext('sale_payment.statement_already_opened',
|
||||
statement=journal.rec_name))
|
||||
results.append(
|
||||
gettext(
|
||||
'sale_payment.statement_already_opened',
|
||||
statement=journal.rec_name))
|
||||
statements.extend(Statement.create(vlist))
|
||||
self.result = '\n'.join(results)
|
||||
else:
|
||||
@@ -202,7 +207,7 @@ class CloseStatementStart(ModelView):
|
||||
statementLines = fields.One2Many('statement.line', None, 'Lines Statement',
|
||||
states={'readonly': True})
|
||||
|
||||
|
||||
|
||||
class CloseStatementDone(ModelView):
|
||||
'Close Statement'
|
||||
__name__ = 'close.statement.done'
|
||||
@@ -222,8 +227,7 @@ class CloseStatement(Wizard):
|
||||
'sale_payment.close_statement_done', [
|
||||
Button('Done', 'end', 'tryton-ok', default=True),
|
||||
])
|
||||
|
||||
|
||||
|
||||
def default_done(self, fields):
|
||||
return {
|
||||
'result': self.result,
|
||||
@@ -232,7 +236,7 @@ class CloseStatement(Wizard):
|
||||
def default_start(self, fields):
|
||||
pool = Pool()
|
||||
User = pool.get('res.user')
|
||||
StatementLine = pool.get('statement.line')
|
||||
# StatementLine = pool.get('statement.line')
|
||||
Statement = pool.get('account.statement')
|
||||
statementLines = []
|
||||
user = Transaction().user
|
||||
@@ -258,12 +262,13 @@ class CloseStatement(Wizard):
|
||||
'journal': s.journal.id,
|
||||
'start_balance': s.start_balance,
|
||||
'balance': end_balance,
|
||||
'end_balance':end_balance+s.start_balance
|
||||
'end_balance': (
|
||||
end_balance + s.start_balance)
|
||||
}
|
||||
statementLines.append(line)
|
||||
|
||||
default = {'statementLines': statementLines}
|
||||
|
||||
|
||||
return default
|
||||
|
||||
def transition_validate(self):
|
||||
@@ -272,12 +277,12 @@ class CloseStatement(Wizard):
|
||||
Statement = pool.get('account.statement')
|
||||
StatementLine = pool.get('account.statement.line')
|
||||
ConfigurationClosure = pool.get('sale.cash_closures')
|
||||
config = ConfigurationClosure(8)
|
||||
config = ConfigurationClosure(8)
|
||||
user = Transaction().user
|
||||
user = User(user)
|
||||
employee_party = user.employee.party.id if user.employee else None
|
||||
device = user.sale_device
|
||||
|
||||
|
||||
if device:
|
||||
journals = [j.id for j in device.journals]
|
||||
draft_statements = {
|
||||
@@ -305,38 +310,45 @@ class CloseStatement(Wizard):
|
||||
if account and transfer:
|
||||
end_balance = abs(end_balance) - abs(transfer)
|
||||
statement.end_balance = end_balance
|
||||
lines = statement.lines
|
||||
# lines = statement.lines
|
||||
conciliation = tuple([StatementLine(
|
||||
date=datetime.today().date(),
|
||||
amount= abs(transfer)*-1,
|
||||
amount=abs(transfer) * -1,
|
||||
account=account.id)]
|
||||
)
|
||||
statement.lines = statement.lines + conciliation
|
||||
|
||||
if mismatch and mismatch.real > 0:
|
||||
pass
|
||||
|
||||
if (config.mismatch_limit and config.account_mismatch_charge):
|
||||
if mismatch and (abs(mismatch) >= abs(config.mismatch_limit.real)):
|
||||
lines = statement.lines
|
||||
if employee_party == None:
|
||||
raise UserError(str("Debe definir un Empleado para el Usuario."))
|
||||
|
||||
if config.mismatch_limit and (
|
||||
config.account_mismatch_charge):
|
||||
if mismatch and (abs(mismatch) >= abs(
|
||||
config.mismatch_limit.real)):
|
||||
# lines = statement.lines
|
||||
if employee_party is None:
|
||||
raise UserError(str(
|
||||
"Debe definir un Empleado para el Usuario."
|
||||
))
|
||||
conciliation_mismatch = tuple([StatementLine(
|
||||
date=datetime.today().date(),
|
||||
amount=mismatch,
|
||||
account=config.account_mismatch_charge.id)]
|
||||
)
|
||||
statement.lines = statement.lines + conciliation_mismatch
|
||||
statement.lines =\
|
||||
statement.lines + conciliation_mismatch
|
||||
end_balance = abs(end_balance) - abs(mismatch)
|
||||
|
||||
|
||||
statement.end_balance = end_balance
|
||||
statement.save()
|
||||
statements.append(statement)
|
||||
results.append(gettext('sale_payment.close_statement',
|
||||
statement=statement.rec_name))
|
||||
elif statement:
|
||||
results.append(gettext('sale_payment.statement_already_closed',
|
||||
statement=statement.rec_name))
|
||||
results.append(
|
||||
gettext(
|
||||
'sale_payment.statement_already_closed',
|
||||
statement=statement.rec_name))
|
||||
else:
|
||||
results.append(gettext('sale_payment.not_statement_found',
|
||||
journal=journal.rec_name))
|
||||
@@ -362,11 +374,13 @@ class StatementLine(ModelView):
|
||||
currency = fields.Many2One(
|
||||
'currency.currency', "Currency")
|
||||
start_balance = Monetary(
|
||||
"Start Balance", currency='currency', digits='currency', states=_states)
|
||||
"Start Balance", currency='currency', digits='currency',
|
||||
states=_states)
|
||||
balance = Monetary(
|
||||
"Balance", currency='currency', digits='currency', states=_states)
|
||||
end_balance = Monetary(
|
||||
"End Balance", currency='currency', digits='currency', readonly=True)
|
||||
"End Balance", currency='currency', digits='currency',
|
||||
readonly=True)
|
||||
transfer = Monetary(
|
||||
"Transfer", currency='currency', digits='currency')
|
||||
real_cash = Monetary(
|
||||
@@ -391,29 +405,35 @@ class StatementLine(ModelView):
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@fields.depends('end_balance', 'real_cash', 'mismatch')
|
||||
def on_change_real_cash(self):
|
||||
self.mismatch = self.real_cash - self.end_balance
|
||||
if self.real_cash and self.end_balance:
|
||||
self.mismatch = self.real_cash - self.end_balance
|
||||
|
||||
|
||||
class PayInvoiceSupplierStart(ModelView):
|
||||
'Payment Invoice To Supplier'
|
||||
__name__ = 'pay_invoice.statement.start'
|
||||
|
||||
invoice_to_pay = fields.One2Many('line_invoice.pay', None, "Invoice To Pay")
|
||||
|
||||
invoice_to_pay = fields.One2Many(
|
||||
'line_invoice.pay', None, "Invoice To Pay")
|
||||
|
||||
|
||||
class PayInvoiceSupplier(Wizard):
|
||||
'Payment Invoice To Supplier'
|
||||
__name__ = 'pay_invoice.statement'
|
||||
|
||||
start = StateView('pay_invoice.statement.start',
|
||||
'sale_payment.pay_invoice_statement_start', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Pay', 'pay', 'tryton-ok', default=True),
|
||||
])
|
||||
start = StateView(
|
||||
'pay_invoice.statement.start',
|
||||
'sale_payment.pay_invoice_statement_start', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Pay', 'pay', 'tryton-ok', default=True),
|
||||
])
|
||||
|
||||
pay = StateAction('account_statement.act_statement_form')
|
||||
|
||||
def do_pay(self, action):
|
||||
pool = Pool()
|
||||
User = pool.get('res.user')
|
||||
@@ -438,17 +458,17 @@ class PayInvoiceSupplier(Wizard):
|
||||
party = pay.party
|
||||
amount = pay.amount
|
||||
statement = draft_statements.get(journal)
|
||||
lines = statement.lines
|
||||
# lines = statement.lines
|
||||
pay_to_add = tuple([StatementLine(
|
||||
date=datetime.today().date(),
|
||||
party=party,
|
||||
related_to=invoice,
|
||||
amount= abs(amount)*-1,
|
||||
amount=abs(amount) * -1,
|
||||
account=account.id)])
|
||||
statement.lines = statement.lines + pay_to_add
|
||||
statement.save()
|
||||
|
||||
|
||||
|
||||
|
||||
class LinesInvoiceToPay(ModelView):
|
||||
"Lines Invoice To Pay"
|
||||
__name__ = 'line_invoice.pay'
|
||||
@@ -457,7 +477,8 @@ class LinesInvoiceToPay(ModelView):
|
||||
'company.company', "Company", required=True)
|
||||
journal = fields.Many2One('account.statement.journal', 'Journal',
|
||||
required=True)
|
||||
amount = Monetary("Amount", currency='currency', digits='currency', required=True)
|
||||
amount = Monetary(
|
||||
"Amount", currency='currency', digits='currency', required=True)
|
||||
party = fields.Many2One('party.party', "Party", required=True,
|
||||
context={'company': Eval('company', -1)},)
|
||||
invoice = fields.Reference(
|
||||
@@ -472,10 +493,10 @@ class LinesInvoiceToPay(ModelView):
|
||||
If(Bool(Eval('account')),
|
||||
('account', '=', Eval('account')),
|
||||
()),
|
||||
If(Eval('statement_state') == 'draft',
|
||||
('state', '=', 'posted'),
|
||||
('state', '!=', '')),
|
||||
],},
|
||||
# If(Eval('statement_state') == 'draft',
|
||||
# ('state', '=', 'posted'),
|
||||
# ('state', '!=', '')),
|
||||
]},
|
||||
context={'with_payment': False})
|
||||
account = fields.Many2One('account.account', "Account",
|
||||
domain=[
|
||||
@@ -484,17 +505,28 @@ class LinesInvoiceToPay(ModelView):
|
||||
('closed', '!=', True),
|
||||
],)
|
||||
description = fields.Char("Description")
|
||||
currency = fields.Many2One(
|
||||
'currency.currency', 'Currency', required=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
@classmethod
|
||||
def default_currency(cls, **pattern):
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
company = pattern.get('company')
|
||||
if not company:
|
||||
company = cls.default_company()
|
||||
if company:
|
||||
return Company(company).currency.id
|
||||
|
||||
@classmethod
|
||||
def _get_relations(cls):
|
||||
"Return a list of Model names for related_to Reference"
|
||||
|
||||
return ['account.invoice']
|
||||
|
||||
return ['account.invoice']
|
||||
|
||||
@classmethod
|
||||
def get_relations(cls):
|
||||
|
||||
Reference in New Issue
Block a user