diff --git a/.#statement.py b/.#statement.py new file mode 120000 index 0000000..65d8213 --- /dev/null +++ b/.#statement.py @@ -0,0 +1 @@ +raskolnikov@rodia.1573466766240099969 \ No newline at end of file diff --git a/__init__.py b/__init__.py index a5ac9e3..833408f 100644 --- a/__init__.py +++ b/__init__.py @@ -13,6 +13,7 @@ def register(): statement.Journal, statement.Statement, statement.Line, + statement.StatementLine, device.SaleDevice, user.User, device.SaleDeviceStatementJournal, diff --git a/__pycache__/__init__.cpython-39.opt-1.pyc b/__pycache__/__init__.cpython-39.opt-1.pyc new file mode 100644 index 0000000..b632f5a Binary files /dev/null and b/__pycache__/__init__.cpython-39.opt-1.pyc differ diff --git a/__pycache__/device.cpython-39.opt-1.pyc b/__pycache__/device.cpython-39.opt-1.pyc new file mode 100644 index 0000000..3c9eb98 Binary files /dev/null and b/__pycache__/device.cpython-39.opt-1.pyc differ diff --git a/__pycache__/sale.cpython-39.opt-1.pyc b/__pycache__/sale.cpython-39.opt-1.pyc new file mode 100644 index 0000000..a707727 Binary files /dev/null and b/__pycache__/sale.cpython-39.opt-1.pyc differ diff --git a/__pycache__/statement.cpython-39.opt-1.pyc b/__pycache__/statement.cpython-39.opt-1.pyc new file mode 100644 index 0000000..33e66d8 Binary files /dev/null and b/__pycache__/statement.cpython-39.opt-1.pyc differ diff --git a/__pycache__/user.cpython-39.opt-1.pyc b/__pycache__/user.cpython-39.opt-1.pyc new file mode 100644 index 0000000..94a654e Binary files /dev/null and b/__pycache__/user.cpython-39.opt-1.pyc differ diff --git a/statement.py b/statement.py index 3e63f70..67ea58e 100644 --- a/statement.py +++ b/statement.py @@ -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' @@ -143,7 +145,7 @@ class OpenStatement(Wizard): return { 'result': self.result, } - + def transition_create_(self): pool = Pool() User = pool.get('res.user') @@ -197,7 +199,9 @@ class CloseStatementStart(ModelView): 'Close Statement' __name__ = 'close.statement.start' + statementLines = fields.One2Many('statement.line', None, 'Lines') + class CloseStatementDone(ModelView): 'Close Statement' __name__ = 'close.statement.done' @@ -217,17 +221,54 @@ class CloseStatement(Wizard): 'sale_payment.close_statement_done', [ 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,15 +283,36 @@ 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) - end_balance = statement.start_balance - for line in statement.lines: - end_balance += line.amount - statement.end_balance = end_balance + 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 + statement.end_balance = end_balance statement.save() statements.append(statement) results.append(gettext('sale_payment.close_statement', @@ -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') diff --git a/statement.xml b/statement.xml index 6fd2ed4..d868aaa 100644 --- a/statement.xml +++ b/statement.xml @@ -55,7 +55,6 @@ copyright notices and license terms. --> - open.statement.start form @@ -70,8 +69,22 @@ copyright notices and license terms. --> Open Statements open.statement - + + statement.line + form + statement_line_form + + + statement.line + tree + + statement_line_tree_sequence + + + diff --git a/view/close_statement_start_form.xml b/view/close_statement_start_form.xml index c75e08e..e898157 100644 --- a/view/close_statement_start_form.xml +++ b/view/close_statement_start_form.xml @@ -2,11 +2,13 @@ -
+