diff --git a/.#statement.py b/.#statement.py
deleted file mode 120000
index 65d8213..0000000
--- a/.#statement.py
+++ /dev/null
@@ -1 +0,0 @@
-raskolnikov@rodia.1573466766240099969
\ No newline at end of file
diff --git a/__init__.py b/__init__.py
index 833408f..71b96ab 100644
--- a/__init__.py
+++ b/__init__.py
@@ -14,6 +14,7 @@ def register():
statement.Statement,
statement.Line,
statement.StatementLine,
+ statement.LinesInvoiceToPay,
device.SaleDevice,
user.User,
device.SaleDeviceStatementJournal,
@@ -23,10 +24,12 @@ def register():
statement.OpenStatementDone,
statement.CloseStatementStart,
statement.CloseStatementDone,
+ statement.PayInvoiceSupplierStart,
module='sale_payment', type_='model')
Pool.register(
sale.WizardSalePayment,
sale.WizardSaleReconcile,
statement.OpenStatement,
statement.CloseStatement,
+ statement.PayInvoiceSupplier,
module='sale_payment', type_='wizard')
diff --git a/__pycache__/__init__.cpython-39.opt-1.pyc b/__pycache__/__init__.cpython-39.opt-1.pyc
index b632f5a..bea736e 100644
Binary files a/__pycache__/__init__.cpython-39.opt-1.pyc and b/__pycache__/__init__.cpython-39.opt-1.pyc differ
diff --git a/__pycache__/statement.cpython-39.opt-1.pyc b/__pycache__/statement.cpython-39.opt-1.pyc
index 33e66d8..39c9217 100644
Binary files a/__pycache__/statement.cpython-39.opt-1.pyc and b/__pycache__/statement.cpython-39.opt-1.pyc differ
diff --git a/statement.py b/statement.py
index 67ea58e..1c2afe8 100644
--- a/statement.py
+++ b/statement.py
@@ -4,11 +4,11 @@
from trytond.model import fields, ModelView
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
-from trytond.wizard import Button, StateTransition, 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
-from trytond.pyson import Eval
+from trytond.pyson import Bool, Eval, If
from trytond.exceptions import UserError
from datetime import datetime
@@ -284,8 +284,6 @@ class CloseStatement(Wizard):
results = []
statements = []
- #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
@@ -305,7 +303,6 @@ class CloseStatement(Wizard):
amount= abs(transfer)*-1,
account=account.id)]
)
- #raise UserError(str(conciliation))
statement.lines = statement.lines + conciliation
else:
@@ -335,11 +332,13 @@ class CloseStatement(Wizard):
class StatementLine(ModelView):
"statement Line"
__name__ = 'statement.line'
-
+
+ _states = {'readonly': True}
company = fields.Many2One(
'company.company', "Company", required=True, select=True)
journal = fields.Many2One('account.statement.journal', 'Journal',
- required=True, select=True)
+ required=True, select=True,
+ states=_states)
currency = fields.Many2One(
'currency.currency', "Currency")
start_balance = Monetary(
@@ -350,13 +349,13 @@ class StatementLine(ModelView):
"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),
- ])
+ account = fields.Many2One('account.account', "Account",
+ domain=[
+ ('company', '=', Eval('company', 0)),
+ ('type', '!=', None),
+ ('closed', '!=', True),
+ ],
+ states={'required': If(Eval('transfer', True), True)})
@staticmethod
def default_currency():
@@ -368,3 +367,117 @@ class StatementLine(ModelView):
@staticmethod
def default_company():
return Transaction().context.get('company')
+
+
+class PayInvoiceSupplierStart(ModelView):
+ 'Payment Invoice To Supplier'
+ __name__ = 'pay_invoice.statement.start'
+
+ invoice_to_pay = fields.One2Many('line_invoice.pay', None, 'Lines 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),
+ ])
+
+ pay = StateAction('account_statement.act_statement_form')
+ def do_pay(self, action):
+ 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
+ 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 pay in self.start.invoice_to_pay:
+ journal = pay.journal
+ account = pay.account
+ invoice = pay.invoice
+ party = pay.party
+ amount = pay.amount
+ statement = draft_statements.get(journal)
+ lines = statement.lines
+ pay_to_add = tuple([StatementLine(
+ date=datetime.today().date(),
+ party=party,
+ related_to=invoice,
+ 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'
+
+ company = fields.Many2One(
+ 'company.company', "Company", required=True, select=True)
+ journal = fields.Many2One('account.statement.journal', 'Journal',
+ required=True, select=True)
+ amount = Monetary(
+ "Amount", currency='currency', digits='currency', required=True)
+ party = fields.Many2One(
+ 'party.party', "Party",
+ context={
+ 'company': Eval('company', -1),
+ },)
+ invoice = fields.Reference(
+ "Related To", 'get_relations', required=True,
+ domain={
+ 'account.invoice': [
+ ('company', '=', Eval('company', -1)),
+ ('type', '=', 'in'),
+ If(Bool(Eval('party')),
+ ('party', '=', Eval('party')),
+ ()),
+ If(Bool(Eval('account')),
+ ('account', '=', Eval('account')),
+ ()),
+ If(Eval('statement_state') == 'draft',
+ ('state', '=', 'posted'),
+ ('state', '!=', '')),
+ ],},
+ context={'with_payment': False})
+ account = fields.Many2One('account.account', "Account",
+ domain=[
+ ('company', '=', Eval('company', 0)),
+ ('type', '!=', None),
+ ('closed', '!=', True),
+ ],)
+ description = fields.Char("Description")
+
+ @staticmethod
+ def default_company():
+ return Transaction().context.get('company')
+
+ @classmethod
+ def _get_relations(cls):
+ "Return a list of Model names for related_to Reference"
+
+ return ['account.invoice']
+
+
+ @classmethod
+ def get_relations(cls):
+ Model = Pool().get('ir.model')
+ get_name = Model.get_name
+ models = cls._get_relations()
+
+ return [(m, get_name(m)) for m in models]
+
+
diff --git a/statement.xml b/statement.xml
index d868aaa..f63521c 100644
--- a/statement.xml
+++ b/statement.xml
@@ -80,6 +80,20 @@ copyright notices and license terms. -->
statement_line_tree_sequence
+
+ Pay Invoice Supplier Statement
+ pay_invoice.statement
+
+
+
+ line_invoice.pay
+ tree
+
+ pay_invoice_line_tree_sequence
+