added balance to close in statement

This commit is contained in:
sinergia 2023-06-21 00:32:14 -05:00
parent 68c503039c
commit 38087ce25c
16 changed files with 152 additions and 14 deletions

1
.#statement.py Symbolic link
View File

@ -0,0 +1 @@
raskolnikov@rodia.1573466766240099969

View File

@ -13,6 +13,7 @@ def register():
statement.Journal,
statement.Statement,
statement.Line,
statement.StatementLine,
device.SaleDevice,
user.User,
device.SaleDeviceStatementJournal,

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,7 +7,10 @@ from trytond.transaction import Transaction
from trytond.wizard import Button, StateTransition, StateView, Wizard
from decimal import Decimal
from trytond.i18n import gettext
from trytond.modules.currency.fields import Monetary
from trytond.pyson import Eval
from trytond.exceptions import UserError
from datetime import datetime
__all__ = ['Journal', 'Statement', 'Line', 'OpenStatementStart',
'OpenStatementDone', 'OpenStatement', 'CloseStatementStart',
@ -118,7 +121,6 @@ class OpenStatementStart(ModelView):
'Open Statement'
__name__ = 'open.statement.start'
class OpenStatementDone(ModelView):
'Open Statement'
__name__ = 'open.statement.done'
@ -197,6 +199,8 @@ class CloseStatementStart(ModelView):
'Close Statement'
__name__ = 'close.statement.start'
statementLines = fields.One2Many('statement.line', None, 'Lines')
class CloseStatementDone(ModelView):
'Close Statement'
@ -218,16 +222,53 @@ class CloseStatement(Wizard):
Button('Done', 'end', 'tryton-ok', default=True),
])
def default_done(self, fields):
return {
'result': self.result,
}
def default_start(self, fields):
pool = Pool()
User = pool.get('res.user')
StatementLine = pool.get('statement.line')
Statement = pool.get('account.statement')
statementLines = []
user = Transaction().user
user = User(user)
device = user.sale_device
if device:
journals = [j.id for j in device.journals]
draft_statements = {
s.journal: s for s in Statement.search([
('journal', 'in', journals),
], order=[
('create_date', 'ASC'),
])}
for s in draft_statements.values():
end_balance = Decimal('0.0')
for line in s.lines:
end_balance += line.amount
line = {
'journal': s.journal.id,
'start_balance': s.start_balance,
'balance': end_balance,
'end_balance':end_balance+s.start_balance
}
statementLines.append(line)
default = {'statementLines': statementLines}
return default
def transition_validate(self):
pool = Pool()
User = pool.get('res.user')
Statement = pool.get('account.statement')
StatementLine = pool.get('account.statement.line')
user = Transaction().user
user = User(user)
device = user.sale_device
@ -242,11 +283,32 @@ class CloseStatement(Wizard):
results = []
statements = []
for journal in device.journals:
#raise UserError(str((device.journals)))
#raise UserError(str((self.start.statementLines[0].journal)))
for journal in self.start.statementLines:
account = journal.account
transfer = journal.transfer
end_balance = journal.end_balance
journal = journal.journal
statement = draft_statements.get(journal)
if statement and statement.state == 'draft':
if not statement.start_balance:
statement.start_balance = Decimal(0)
if account and transfer:
end_balance = abs(end_balance) - abs(transfer)
statement.end_balance = end_balance
lines = statement.lines
conciliation = tuple([StatementLine(
date=datetime.today().date(),
amount= abs(transfer)*-1,
account=account.id)]
)
#raise UserError(str(conciliation))
statement.lines = statement.lines + conciliation
else:
end_balance = statement.start_balance
for line in statement.lines:
end_balance += line.amount
@ -268,3 +330,41 @@ class CloseStatement(Wizard):
self.result = gettext('sale_payment.user_without_device',
user=user.rec_name)
return 'done'
class StatementLine(ModelView):
"statement Line"
__name__ = 'statement.line'
company = fields.Many2One(
'company.company', "Company", required=True, select=True)
journal = fields.Many2One('account.statement.journal', 'Journal',
required=True, select=True)
currency = fields.Many2One(
'currency.currency', "Currency")
start_balance = Monetary(
"Start Balance", currency='currency', digits='currency')
balance = Monetary(
"Balance", currency='currency', digits='currency')
transfer = Monetary(
"Transfer", currency='currency', digits='currency')
end_balance = Monetary(
"End Balance", currency='currency', digits='currency')
account = fields.Many2One(
'account.account', "Account",
domain=[
('company', '=', Eval('company', 0)),
('type', '!=', None),
('closed', '!=', True),
])
@staticmethod
def default_currency():
Company = Pool().get('company.company')
company = Transaction().context.get('company')
if company:
return Company(company).currency.id
@staticmethod
def default_company():
return Transaction().context.get('company')

View File

@ -55,7 +55,6 @@ copyright notices and license terms. -->
<menuitem name="Statements" parent="sale.menu_sale"
action="act_sale_statement_form"
id="menu_sale_statement" sequence="70"/>
<record model="ir.ui.view" id="open_statement_start">
<field name="model">open.statement.start</field>
<field name="type">form</field>
@ -70,8 +69,22 @@ copyright notices and license terms. -->
<field name="name">Open Statements</field>
<field name="wiz_name">open.statement</field>
</record>
<menuitem parent="menu_sale_statement"
action="wizard_open_statement" id="menu_open_statement"/>
<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">
<field name="model">statement.line</field>
<field name="type">tree</field>
<field name="priority" eval="20"/>
<field name="name">statement_line_tree_sequence</field>
</record>
<menuitem
parent="menu_sale_statement"
action="wizard_open_statement"
id="menu_open_statement"/>
<record model="ir.ui.menu-res.group" id="menu_open_statement_group">
<field name="menu" ref="menu_open_statement"/>
<field name="group" ref="account_statement.group_statement"/>

View File

@ -2,11 +2,13 @@
<!-- This file is part of the sale_payment module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<form col="2">
<form>
<image name="tryton-info" xexpand="0"
xfill="0"/>
<label
string="You are going to close statements of your device."
id="create"
yalign="0.0" xalign="0.0" xexpand="1"/>
<newline/>
<field name="statementLines"/>
</form>

View File

@ -9,4 +9,5 @@ copyright notices and license terms. -->
string="You are going to open statements of your device."
id="create"
yalign="0.0" xalign="0.0" xexpand="1"/>
<newline/>
</form>

View File

View File

@ -0,0 +1,9 @@
<?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>

View File

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- This file is part of 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="balance"/>
<field name="end_balance"/>
<field name="transfer"/>
<field name="account"/>
</tree>

View File