Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sale_automatic_workflow/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Contributors
- Sander Lienaerts <sander.lienaerts@codeforward.nl>
- Tri Doan <tridm@trobz.com>
- Chau Le <chaulb@trobz.com>
- Kevin Khao <kevinkhao@gmail.com>

Other credits
-------------
Expand Down
2 changes: 1 addition & 1 deletion sale_automatic_workflow/data/automatic_workflow_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<field name="model_id">account.move</field>
<field
name="domain"
>[('state', '=', 'posted'), ('move_type', '=', 'out_invoice'), ('payment_state','!=','paid')]</field>
>[('state', '=', 'posted'), ('move_type', '=', 'out_invoice'), ('payment_state','=','not_paid')]</field>
<field name="user_ids" eval="[(4, ref('base.user_root'))]" />
</record>
<record id="automatic_validation" model="sale.workflow.process">
Expand Down
15 changes: 13 additions & 2 deletions sale_automatic_workflow/models/automatic_workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,20 @@ def _prepare_dict_account_payment(self, invoice):
and "customer"
or "supplier"
)
return {
res = {
"reconciled_invoice_ids": [(6, 0, invoice.ids)],
"amount": invoice.amount_residual,
"partner_id": invoice.partner_id.id,
"partner_type": partner_type,
"date": fields.Date.context_today(self),
"currency_id": invoice.currency_id.id,
}
property_payment_journal_id = (
invoice.workflow_process_id.property_payment_journal_id
)
if property_payment_journal_id:
res["journal_id"] = property_payment_journal_id.id
return res

@api.model
def _register_payments(self, payment_filter):
Expand All @@ -160,7 +166,11 @@ def _register_payment_invoice(self, invoice):
payment.action_post()

domain = [
("account_type", "in", ("asset_receivable", "liability_payable")),
(
"account_type",
"in",
self.env["account.payment"]._get_valid_payment_account_types(),
),
("reconciled", "=", False),
]
payment_lines = payment.move_id.line_ids.filtered_domain(domain)
Expand All @@ -169,6 +179,7 @@ def _register_payment_invoice(self, invoice):
(payment_lines + lines).filtered_domain(
[("account_id", "=", account.id), ("reconciled", "=", False)]
).reconcile()
lines.move_id.matched_payment_ids += payment
return payment

@api.model
Expand Down
6 changes: 6 additions & 0 deletions sale_automatic_workflow/models/sale_workflow_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def _default_filter(self, xmlid):
string="Sales Journal",
help="Set default journal to use on invoice",
)
property_payment_journal_id = fields.Many2one(
comodel_name="account.journal",
company_dependent=True,
string="Payment Journal",
help="Set default journal to use on payment",
)
order_filter_id = fields.Many2one(
"ir.filters",
default=lambda self: self._default_filter(
Expand Down
1 change: 1 addition & 0 deletions sale_automatic_workflow/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
- Sander Lienaerts \<<sander.lienaerts@codeforward.nl>\>
- Tri Doan \<<tridm@trobz.com>\>
- Chau Le \<<chaulb@trobz.com>\>
- Kevin Khao \<<kevinkhao@gmail.com>\>
1 change: 1 addition & 0 deletions sale_automatic_workflow/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ <h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
<li>Sander Lienaerts &lt;<a class="reference external" href="mailto:sander.lienaerts&#64;codeforward.nl">sander.lienaerts&#64;codeforward.nl</a>&gt;</li>
<li>Tri Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
<li>Chau Le &lt;<a class="reference external" href="mailto:chaulb&#64;trobz.com">chaulb&#64;trobz.com</a>&gt;</li>
<li>Kevin Khao &lt;<a class="reference external" href="mailto:kevinkhao&#64;gmail.com">kevinkhao&#64;gmail.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
13 changes: 13 additions & 0 deletions sale_automatic_workflow/tests/test_automatic_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,16 @@ def test_create_payment_with_invoice_currency_id(self):
)
self.assertTrue(payment_id)
self.assertEqual(invoice.currency_id.id, payment_id.currency_id.id)
self.assertEqual(invoice.payment_state, invoice._get_invoice_in_payment_state())

def test_create_payment_with_specified_payment_journal(self):
workflow = self.create_full_automatic()
workflow.register_payment = True
payment_journal = self.env["account.journal"].create(
{"name": "Payment Journal Test", "code": "TESTJOURNAL", "type": "bank"}
)
workflow.property_payment_journal_id = payment_journal
self.create_sale_order(workflow)
self.run_job()
payment = self.env["account.payment"].search([], limit=1, order="id desc")
self.assertEqual(payment.journal_id, payment_journal)
13 changes: 13 additions & 0 deletions sale_automatic_workflow/views/sale_workflow_process_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@
<field name="property_journal_id" nolabel="1" />
</div>
</div>
<div
class="row"
groups="account.group_account_invoice"
domain="[('type', '=', 'sale')]"
>
<div class="col-sm-12">
<label
for="property_payment_journal_id"
class="col-lg-4 o_light_label"
/>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (non-blocking, pre-existing pattern): the <field> for the payment journal could benefit from a domain="[('type', 'in', ('bank', 'cash'))]" to restrict the selection to bank/cash journals, since it wouldn't make sense to register payments against a sales or miscellaneous journal. The existing property_journal_id has the same gap though, so this is more of a follow-up improvement for both fields.

<field name="property_payment_journal_id" nolabel="1" />
</div>
</div>
<br />
<div class="row">
<div class="col-sm-12">
Expand Down