added pay to invoice supplier with wizard

This commit is contained in:
sinergia 2023-06-21 11:28:46 -05:00
parent a5705f1818
commit 1168dffad6
9 changed files with 171 additions and 20 deletions

View File

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

View File

@ -14,6 +14,7 @@ def register():
statement.Statement, statement.Statement,
statement.Line, statement.Line,
statement.StatementLine, statement.StatementLine,
statement.LinesInvoiceToPay,
device.SaleDevice, device.SaleDevice,
user.User, user.User,
device.SaleDeviceStatementJournal, device.SaleDeviceStatementJournal,
@ -23,10 +24,12 @@ def register():
statement.OpenStatementDone, statement.OpenStatementDone,
statement.CloseStatementStart, statement.CloseStatementStart,
statement.CloseStatementDone, statement.CloseStatementDone,
statement.PayInvoiceSupplierStart,
module='sale_payment', type_='model') module='sale_payment', type_='model')
Pool.register( Pool.register(
sale.WizardSalePayment, sale.WizardSalePayment,
sale.WizardSaleReconcile, sale.WizardSaleReconcile,
statement.OpenStatement, statement.OpenStatement,
statement.CloseStatement, statement.CloseStatement,
statement.PayInvoiceSupplier,
module='sale_payment', type_='wizard') module='sale_payment', type_='wizard')

View File

@ -4,11 +4,11 @@
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, 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
from trytond.pyson import Eval from trytond.pyson import Bool, Eval, If
from trytond.exceptions import UserError from trytond.exceptions import UserError
from datetime import datetime from datetime import datetime
@ -284,8 +284,6 @@ class CloseStatement(Wizard):
results = [] results = []
statements = [] statements = []
#raise UserError(str((device.journals)))
#raise UserError(str((self.start.statementLines[0].journal)))
for journal in self.start.statementLines: for journal in self.start.statementLines:
account = journal.account account = journal.account
transfer = journal.transfer transfer = journal.transfer
@ -305,7 +303,6 @@ class CloseStatement(Wizard):
amount= abs(transfer)*-1, amount= abs(transfer)*-1,
account=account.id)] account=account.id)]
) )
#raise UserError(str(conciliation))
statement.lines = statement.lines + conciliation statement.lines = statement.lines + conciliation
else: else:
@ -335,11 +332,13 @@ class CloseStatement(Wizard):
class StatementLine(ModelView): class StatementLine(ModelView):
"statement Line" "statement Line"
__name__ = 'statement.line' __name__ = 'statement.line'
_states = {'readonly': True}
company = fields.Many2One( company = fields.Many2One(
'company.company', "Company", required=True, select=True) 'company.company', "Company", required=True, select=True)
journal = fields.Many2One('account.statement.journal', 'Journal', journal = fields.Many2One('account.statement.journal', 'Journal',
required=True, select=True) required=True, select=True,
states=_states)
currency = fields.Many2One( currency = fields.Many2One(
'currency.currency', "Currency") 'currency.currency', "Currency")
start_balance = Monetary( start_balance = Monetary(
@ -350,13 +349,13 @@ class StatementLine(ModelView):
"Transfer", currency='currency', digits='currency') "Transfer", currency='currency', digits='currency')
end_balance = Monetary( end_balance = Monetary(
"End Balance", currency='currency', digits='currency') "End Balance", currency='currency', digits='currency')
account = fields.Many2One( account = fields.Many2One('account.account', "Account",
'account.account', "Account", domain=[
domain=[ ('company', '=', Eval('company', 0)),
('company', '=', Eval('company', 0)), ('type', '!=', None),
('type', '!=', None), ('closed', '!=', True),
('closed', '!=', True), ],
]) states={'required': If(Eval('transfer', True), True)})
@staticmethod @staticmethod
def default_currency(): def default_currency():
@ -368,3 +367,117 @@ class StatementLine(ModelView):
@staticmethod @staticmethod
def default_company(): def default_company():
return Transaction().context.get('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]

View File

@ -80,6 +80,20 @@ copyright notices and license terms. -->
<field name="priority" eval="20"/> <field name="priority" eval="20"/>
<field name="name">statement_line_tree_sequence</field> <field name="name">statement_line_tree_sequence</field>
</record> </record>
<record model="ir.action.wizard" id="wizard_pay_invoice_statement">
<field name="name">Pay Invoice Supplier Statement</field>
<field name="wiz_name">pay_invoice.statement</field>
</record>
<menuitem
parent="sale.menu_sale"
action="wizard_pay_invoice_statement"
id="menu_pay_invoice_statement"/>
<record model="ir.ui.view" id="pay_invoice_line_view_tree_sequence">
<field name="model">line_invoice.pay</field>
<field name="type">tree</field>
<field name="priority" eval="20"/>
<field name="name">pay_invoice_line_tree_sequence</field>
</record>
<menuitem <menuitem
parent="menu_sale_statement" parent="menu_sale_statement"
action="wizard_open_statement" action="wizard_open_statement"
@ -100,6 +114,11 @@ copyright notices and license terms. -->
<field name="type">form</field> <field name="type">form</field>
<field name="name">close_statement_done_form</field> <field name="name">close_statement_done_form</field>
</record> </record>
<record model="ir.ui.view" id="pay_invoice_statement_start">
<field name="model">pay_invoice.statement.start</field>
<field name="type">form</field>
<field name="name">pay_invoice_statement_start_form</field>
</record>
<record model="ir.action.wizard" id="wizard_close_statement"> <record model="ir.action.wizard" id="wizard_close_statement">
<field name="name">Close Statements</field> <field name="name">Close Statements</field>
<field name="wiz_name">close.statement</field> <field name="wiz_name">close.statement</field>

View File

@ -2,13 +2,12 @@
<!-- 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> <form col="2">
<image name="tryton-info" xexpand="0" <image name="tryton-info" xexpand="0"/>
xfill="0"/> <newline/>
<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" xexpand="1"/>
yalign="0.0" xalign="0.0" xexpand="1"/>
<newline/> <newline/>
<field name="statementLines"/> <field name="statementLines"/>
</form> </form>

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="party"/>
<field name="invoice"/>
<field name="amount"/>
<field name="account"/>
<field name="description"/>
</tree>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!-- 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>
<field name="invoice_to_pay"/>
</form>