Fix: Autopep8

This commit is contained in:
sinergia 2024-10-21 20:45:58 -05:00
parent 23fa2996a6
commit 4ebe44ae45
10 changed files with 137 additions and 113 deletions

View File

@ -8,9 +8,9 @@ from . import statement
from . import user from . import user
from . import configuration_statement from . import configuration_statement
def register(): def register():
Pool.register( Pool.register(
configuration_statement.Configuration,
statement.Journal, statement.Journal,
statement.Statement, statement.Statement,
statement.Line, statement.Line,
@ -27,6 +27,7 @@ def register():
statement.CloseStatementStart, statement.CloseStatementStart,
statement.CloseStatementDone, statement.CloseStatementDone,
statement.PayInvoiceSupplierStart, statement.PayInvoiceSupplierStart,
configuration_statement.Configuration,
module='sale_payment', type_='model') module='sale_payment', type_='model')
Pool.register( Pool.register(
sale.WizardSalePayment, sale.WizardSalePayment,

View File

@ -6,6 +6,7 @@ from trytond.pyson import Eval
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.pool import Pool from trytond.pool import Pool
class Configuration(ModelSingleton, ModelView, ModelSQL): class Configuration(ModelSingleton, ModelView, ModelSQL):
"Configuration Chas Closures" "Configuration Chas Closures"
__name__ = 'sale.cash_closures' __name__ = 'sale.cash_closures'
@ -17,19 +18,21 @@ class Configuration(ModelSingleton, ModelView, ModelSQL):
mismatch_limit = Monetary( mismatch_limit = Monetary(
"Mismatch Limit", currency='currency', digits='currency') "Mismatch Limit", currency='currency', digits='currency')
account_mismatch_charge = fields.Many2One('account.account', "Account Mismatch Charge", account_mismatch_charge = fields.Many2One(
domain=[ 'account.account', "Account Mismatch Charge",
('company', '=', Eval('company', 0)), domain=[
('type', '!=', None), ('company', '=', Eval('company', 0)),
('closed', '!=', True), ('type', '!=', None),
],) ('closed', '!=', True),
],)
account_mismatch_positive = fields.Many2One(
'account.account', "Account Mismatch Positivo",
domain=[
('company', '=', Eval('company', 0)),
('type', '!=', None),
('closed', '!=', True),
],)
account_mismatch_positive = fields.Many2One('account.account', "Account Mismatch Positivo",
domain=[
('company', '=', Eval('company', 0)),
('type', '!=', None),
('closed', '!=', True),
],)
@staticmethod @staticmethod
def default_currency(): def default_currency():
Company = Pool().get('company.company') Company = Pool().get('company.company')
@ -39,4 +42,4 @@ class Configuration(ModelSingleton, ModelView, ModelSQL):
@staticmethod @staticmethod
def default_company(): def default_company():
return Transaction().context.get('company') return Transaction().context.get('company')

29
sale.py
View File

@ -162,16 +162,17 @@ class Sale(metaclass=PoolMeta):
condition=(sale.id == payline.sale) condition=(sale.id == payline.sale)
).select( ).select(
sale.id, sale.id,
where=((sale.total_amount_cache != None) & where=((sale.total_amount_cache) & (
(sale.state.in_([ sale.state.in_([
'draft', 'draft',
'quotation', 'quotation',
'confirmed', 'confirmed',
'processing', 'processing',
'done']))), 'done']))),
group_by=(sale.id), group_by=(sale.id),
having=(Operator(sale.total_amount_cache - having=(Operator(
Sum(Coalesce(payline.amount, 0)), value) sale.total_amount_cache - Sum(
Coalesce(payline.amount, 0)), value)
)) ))
return [('id', 'in', query)] return [('id', 'in', query)]
@ -196,17 +197,17 @@ class Sale(metaclass=PoolMeta):
class ChangePaymentMethodForm(ModelView): class ChangePaymentMethodForm(ModelView):
'Change Payments Method form' 'Change Payments Method form'
__name__ = 'sale.change_payment_method.form' __name__ = 'sale.change_payment_method.form'
sale = fields.Many2One('sale.sale', "Sale", required=True) sale = fields.Many2One('sale.sale', "Sale", required=True)
statement = fields.Many2One('account.statement', 'Statement Journal', statement = fields.Many2One('account.statement', 'Statement Journal',
domain=[ domain=[
('id', 'in', Eval('statements', [])), ('id', 'in', Eval('statements', [])),
], ], required=True)
depends=['journals'], required=True)
statements = fields.One2Many('account.statement', None, statements = fields.One2Many('account.statement', None,
'Allowed Statement', readonly=True) 'Allowed Statement', readonly=True)
payment = fields.Many2One( payment = fields.Many2One(
'account.statement.line', "Payment", required=True, 'account.statement.line', "Payment", required=True,
domain=[('sale.id', '=', Eval('sale'))]) domain=[('sale', '=', Eval('sale'))])
class ChangePaymentMethod(Wizard): class ChangePaymentMethod(Wizard):
@ -379,8 +380,8 @@ class WizardSaleReconcile(Wizard):
if not payment.move: if not payment.move:
continue continue
for line in payment.move.lines: for line in payment.move.lines:
if (not line.reconciliation and if (not line.reconciliation and (
line.account == account): line.account == account)):
lines.append(line) lines.append(line)
amount += line.debit - line.credit amount += line.debit - line.credit
if lines and amount == Decimal('0.0'): if lines and amount == Decimal('0.0'):

View File

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

View File

@ -4,25 +4,6 @@ The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. --> copyright notices and license terms. -->
<tryton> <tryton>
<data> <data>
<record model="ir.action.act_window" id="act_configuration_closures_form">
<field name="name">Configuration Closures</field>
<field name="res_model">sale.cash_closures</field>
</record>
<record model="ir.ui.view" id="configuration_closures_view_form">
<field name="model">sale.cash_closures</field>
<field name="type">form</field>
<field name="name">configuration_closures_form</field>
</record>
<record model="ir.action.act_window.view" id="act_prospect_form_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="configuration_closures_view_form"/>
<field name="act_window" ref="act_configuration_closures_form"/>
</record>
<menuitem
parent="sale.menu_configuration"
sequence="10"
id="menu_configuration_closure"
action="act_configuration_closures_form"/>
<record model="ir.action.act_window" id="act_sale_statement_form"> <record model="ir.action.act_window" id="act_sale_statement_form">
<field name="name">Statements</field> <field name="name">Statements</field>
<field name="res_model">account.statement</field> <field name="res_model">account.statement</field>
@ -87,11 +68,6 @@ copyright notices and license terms. -->
<field name="name">Open Statements</field> <field name="name">Open Statements</field>
<field name="wiz_name">open.statement</field> <field name="wiz_name">open.statement</field>
</record> </record>
<record model="ir.ui.view" id="statement_line_view_form">
<field name="model">statement.line</field>
<field name="type">form</field>
<field name="name">statement_line_form</field>
</record>
<record model="ir.ui.view" id="statement_line_view_tree_sequence"> <record model="ir.ui.view" id="statement_line_view_tree_sequence">
<field name="model">statement.line</field> <field name="model">statement.line</field>
<field name="type">tree</field> <field name="type">tree</field>
@ -148,6 +124,26 @@ copyright notices and license terms. -->
<field name="group" ref="account_statement.group_statement"/> <field name="group" ref="account_statement.group_statement"/>
</record> </record>
<record model="ir.action.act_window" id="act_configuration_closures_form">
<field name="name">Configuration Closures</field>
<field name="res_model">sale.cash_closures</field>
</record>
<record model="ir.ui.view" id="configuration_closures_view_form">
<field name="model">sale.cash_closures</field>
<field name="type">form</field>
<field name="name">configuration_closures_form</field>
</record>
<record model="ir.action.act_window.view" id="act_prospect_form_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="configuration_closures_view_form"/>
<field name="act_window" ref="act_configuration_closures_form"/>
</record>
<menuitem
parent="sale.menu_configuration"
sequence="10"
id="menu_configuration_closure"
action="act_configuration_closures_form"/>
<record model="ir.model.access" id="access_sale_statement"> <record model="ir.model.access" id="access_sale_statement">
<field name="model" search="[('model', '=', 'account.statement')]"/> <field name="model" search="[('model', '=', 'account.statement')]"/>
<field name="group" ref="sale.group_sale"/> <field name="group" ref="sale.group_sale"/>

View File

@ -19,7 +19,6 @@ Imports::
>>> today = datetime.date.today() >>> today = datetime.date.today()
Install sale:: Install sale::
>>> config = activate_modules(['party', 'sale_payment']) >>> config = activate_modules(['party', 'sale_payment'])
Create company:: Create company::

View File

@ -20,4 +20,5 @@ def load_tests(loader, tests, pattern):
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
finally: finally:
os.chdir(cwd) os.chdir(cwd)
return tests
return tests

View File

@ -4,8 +4,8 @@ depends:
account_statement account_statement
sale_shop sale_shop
xml: xml:
statement.xml
device.xml device.xml
sale.xml sale.xml
statement.xml
user.xml user.xml
message.xml message.xml

View File

@ -1,9 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part sale_pos module for Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree editable="1">
<field name="journal"/>
<field name="start_balance"/>
<field name="current_balance"/>
<field name="account"/>
</tree>