added balance to close in statement
This commit is contained in:
parent
68c503039c
commit
38087ce25c
1
.#statement.py
Symbolic link
1
.#statement.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
raskolnikov@rodia.1573466766240099969
|
@ -13,6 +13,7 @@ def register():
|
|||||||
statement.Journal,
|
statement.Journal,
|
||||||
statement.Statement,
|
statement.Statement,
|
||||||
statement.Line,
|
statement.Line,
|
||||||
|
statement.StatementLine,
|
||||||
device.SaleDevice,
|
device.SaleDevice,
|
||||||
user.User,
|
user.User,
|
||||||
device.SaleDeviceStatementJournal,
|
device.SaleDeviceStatementJournal,
|
||||||
|
BIN
__pycache__/__init__.cpython-39.opt-1.pyc
Normal file
BIN
__pycache__/__init__.cpython-39.opt-1.pyc
Normal file
Binary file not shown.
BIN
__pycache__/device.cpython-39.opt-1.pyc
Normal file
BIN
__pycache__/device.cpython-39.opt-1.pyc
Normal file
Binary file not shown.
BIN
__pycache__/sale.cpython-39.opt-1.pyc
Normal file
BIN
__pycache__/sale.cpython-39.opt-1.pyc
Normal file
Binary file not shown.
BIN
__pycache__/statement.cpython-39.opt-1.pyc
Normal file
BIN
__pycache__/statement.cpython-39.opt-1.pyc
Normal file
Binary file not shown.
BIN
__pycache__/user.cpython-39.opt-1.pyc
Normal file
BIN
__pycache__/user.cpython-39.opt-1.pyc
Normal file
Binary file not shown.
120
statement.py
120
statement.py
@ -7,7 +7,10 @@ from trytond.transaction import Transaction
|
|||||||
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
from trytond.wizard import Button, StateTransition, 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.pyson import Eval
|
||||||
|
from trytond.exceptions import UserError
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
__all__ = ['Journal', 'Statement', 'Line', 'OpenStatementStart',
|
__all__ = ['Journal', 'Statement', 'Line', 'OpenStatementStart',
|
||||||
'OpenStatementDone', 'OpenStatement', 'CloseStatementStart',
|
'OpenStatementDone', 'OpenStatement', 'CloseStatementStart',
|
||||||
@ -118,7 +121,6 @@ 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'
|
||||||
@ -143,7 +145,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')
|
||||||
@ -197,7 +199,9 @@ class CloseStatementStart(ModelView):
|
|||||||
'Close Statement'
|
'Close Statement'
|
||||||
__name__ = 'close.statement.start'
|
__name__ = 'close.statement.start'
|
||||||
|
|
||||||
|
statementLines = fields.One2Many('statement.line', None, 'Lines')
|
||||||
|
|
||||||
|
|
||||||
class CloseStatementDone(ModelView):
|
class CloseStatementDone(ModelView):
|
||||||
'Close Statement'
|
'Close Statement'
|
||||||
__name__ = 'close.statement.done'
|
__name__ = 'close.statement.done'
|
||||||
@ -217,17 +221,54 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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):
|
def transition_validate(self):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
User = pool.get('res.user')
|
User = pool.get('res.user')
|
||||||
Statement = pool.get('account.statement')
|
Statement = pool.get('account.statement')
|
||||||
|
StatementLine = pool.get('account.statement.line')
|
||||||
user = Transaction().user
|
user = Transaction().user
|
||||||
user = User(user)
|
user = User(user)
|
||||||
device = user.sale_device
|
device = user.sale_device
|
||||||
@ -242,15 +283,36 @@ class CloseStatement(Wizard):
|
|||||||
|
|
||||||
results = []
|
results = []
|
||||||
statements = []
|
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)
|
statement = draft_statements.get(journal)
|
||||||
|
|
||||||
if statement and statement.state == 'draft':
|
if statement and statement.state == 'draft':
|
||||||
if not statement.start_balance:
|
if not statement.start_balance:
|
||||||
statement.start_balance = Decimal(0)
|
statement.start_balance = Decimal(0)
|
||||||
end_balance = statement.start_balance
|
if account and transfer:
|
||||||
for line in statement.lines:
|
end_balance = abs(end_balance) - abs(transfer)
|
||||||
end_balance += line.amount
|
statement.end_balance = end_balance
|
||||||
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
|
||||||
|
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',
|
||||||
@ -268,3 +330,41 @@ class CloseStatement(Wizard):
|
|||||||
self.result = gettext('sale_payment.user_without_device',
|
self.result = gettext('sale_payment.user_without_device',
|
||||||
user=user.rec_name)
|
user=user.rec_name)
|
||||||
return 'done'
|
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')
|
||||||
|
@ -55,7 +55,6 @@ copyright notices and license terms. -->
|
|||||||
<menuitem name="Statements" parent="sale.menu_sale"
|
<menuitem name="Statements" parent="sale.menu_sale"
|
||||||
action="act_sale_statement_form"
|
action="act_sale_statement_form"
|
||||||
id="menu_sale_statement" sequence="70"/>
|
id="menu_sale_statement" sequence="70"/>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="open_statement_start">
|
<record model="ir.ui.view" id="open_statement_start">
|
||||||
<field name="model">open.statement.start</field>
|
<field name="model">open.statement.start</field>
|
||||||
<field name="type">form</field>
|
<field name="type">form</field>
|
||||||
@ -70,8 +69,22 @@ 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>
|
||||||
<menuitem parent="menu_sale_statement"
|
<record model="ir.ui.view" id="statement_line_view_form">
|
||||||
action="wizard_open_statement" id="menu_open_statement"/>
|
<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">
|
<record model="ir.ui.menu-res.group" id="menu_open_statement_group">
|
||||||
<field name="menu" ref="menu_open_statement"/>
|
<field name="menu" ref="menu_open_statement"/>
|
||||||
<field name="group" ref="account_statement.group_statement"/>
|
<field name="group" ref="account_statement.group_statement"/>
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
<!-- This file is part of the sale_payment module for Tryton.
|
<!-- This file is part of the sale_payment module for Tryton.
|
||||||
The COPYRIGHT file at the top level of this repository contains the full
|
The COPYRIGHT file at the top level of this repository contains the full
|
||||||
copyright notices and license terms. -->
|
copyright notices and license terms. -->
|
||||||
<form col="2">
|
<form>
|
||||||
<image name="tryton-info" xexpand="0"
|
<image name="tryton-info" xexpand="0"
|
||||||
xfill="0"/>
|
xfill="0"/>
|
||||||
<label
|
<label
|
||||||
string="You are going to close statements of your device."
|
string="You are going to close statements of your device."
|
||||||
id="create"
|
id="create"
|
||||||
yalign="0.0" xalign="0.0" xexpand="1"/>
|
yalign="0.0" xalign="0.0" xexpand="1"/>
|
||||||
|
<newline/>
|
||||||
|
<field name="statementLines"/>
|
||||||
</form>
|
</form>
|
||||||
|
@ -9,4 +9,5 @@ copyright notices and license terms. -->
|
|||||||
string="You are going to open statements of your device."
|
string="You are going to open statements of your device."
|
||||||
id="create"
|
id="create"
|
||||||
yalign="0.0" xalign="0.0" xexpand="1"/>
|
yalign="0.0" xalign="0.0" xexpand="1"/>
|
||||||
|
<newline/>
|
||||||
</form>
|
</form>
|
||||||
|
0
view/statement_line_form.xml
Normal file
0
view/statement_line_form.xml
Normal file
9
view/statement_line_tree.xml
Normal file
9
view/statement_line_tree.xml
Normal 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>
|
0
view/statement_line_tree.xml~
Normal file
0
view/statement_line_tree.xml~
Normal file
11
view/statement_line_tree_sequence.xml
Normal file
11
view/statement_line_tree_sequence.xml
Normal 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>
|
0
view/statement_line_tree_sequence.xml~
Normal file
0
view/statement_line_tree_sequence.xml~
Normal file
Loading…
Reference in New Issue
Block a user