-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
from . import account_payment | ||
from . import account_move_line | ||
from . import account_move | ||
from . import account_journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# © 2024 ADHOC SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, _ | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class AccountJournal(models.Model): | ||
|
||
_inherit = "account.journal" | ||
|
||
def _get_manual_payment_method_id(self, direction='inbound'): | ||
self.ensure_one() | ||
if direction == 'inbound': | ||
payment_method = self.inbound_payment_method_line_ids.payment_method_id.filtered(lambda x: x.code == 'manual') | ||
else: | ||
payment_method = self.outbound_payment_method_line_ids.payment_method_id.filtered(lambda x: x.code == 'manual') | ||
if not payment_method: | ||
raise ValidationError(_('Journal must have manual method!')) | ||
return payment_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# © 2016 ADHOC SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, api, Command, fields, _ | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
open_move_line_ids = fields.One2many( | ||
'account.move.line', | ||
compute='_compute_open_move_lines' | ||
) | ||
pay_now_journal_id = fields.Many2one( | ||
'account.journal', | ||
'Pay now Journal', | ||
help='If you set a journal here, after invoice validation, the invoice' | ||
' will be automatically paid with this journal. As manual payment' | ||
'method is used, only journals with manual method are shown.', | ||
# use copy false for two reasons: | ||
# 1. when making refund it's safer to make pay now empty (specially if automatic refund validation is enable) | ||
# 2. on duplicating an invoice it's safer also | ||
copy=False, | ||
) | ||
|
||
@api.depends('line_ids.account_id.account_type', 'line_ids.reconciled') | ||
def _compute_open_move_lines(self): | ||
for rec in self: | ||
rec.open_move_line_ids = rec.line_ids.filtered( | ||
lambda r: not r.reconciled and r.parent_state == 'posted' and | ||
r.account_id.account_type in self.env['account.payment']._get_valid_payment_account_types()) | ||
|
||
def pay_now(self): | ||
for rec in self.filtered(lambda x: x.pay_now_journal_id and x.state == 'posted' and | ||
x.payment_state in ('not_paid', 'patial')): | ||
pay_journal = rec.pay_now_journal_id | ||
if rec.move_type in ['in_invoice', 'in_refund']: | ||
partner_type = 'supplier' | ||
else: | ||
partner_type = 'customer' | ||
|
||
payment_type = 'inbound' | ||
payment_method = pay_journal._get_manual_payment_method_id(payment_type) | ||
|
||
payment = rec.env[ | ||
'account.payment'].create({ | ||
'date': rec.invoice_date, | ||
'partner_id': rec.commercial_partner_id.id, | ||
'partner_type': partner_type, | ||
'payment_type': payment_type, | ||
'company_id': rec.company_id.id, | ||
'journal_id': pay_journal.id, | ||
'payment_method_id': payment_method.id, | ||
'to_pay_move_line_ids': [Command.set(rec.open_move_line_ids.ids)], | ||
}) | ||
|
||
# el difference es positivo para facturas (de cliente o proveedor) pero negativo para NC. | ||
# para factura de proveedor o NC de cliente es outbound | ||
# para factura de cliente o NC de proveedor es inbound | ||
# igualmente lo hacemos con el difference y no con el type por las dudas de que facturas en negativo | ||
if (partner_type == 'supplier' and payment.payment_difference >= 0.0 or | ||
partner_type == 'customer' and payment.payment_difference < 0.0): | ||
payment.payment_type = 'outbound' | ||
payment.payment_method_id = pay_journal._get_manual_payment_method_id(payment_type).id | ||
payment.amount = abs(payment.payment_difference) | ||
payment.action_post() | ||
|
||
@api.onchange('journal_id') | ||
def _onchange_journal_reset_pay_now(self): | ||
# while not always it should be reseted (only if changing company) it's not so usual to set pay now first | ||
# and then change journal | ||
self.pay_now_journal_id = False | ||
|
||
def button_draft(self): | ||
self.filtered(lambda x: x.state == 'posted' and x.pay_now_journal_id).write({'pay_now_journal_id': False}) | ||
return super().button_draft() | ||
|
||
def _post(self, soft=False): | ||
res = super()._post(soft=soft) | ||
self.pay_now() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<data noupdate="0"> | ||
<record model="res.groups" id="group_pay_now_customer_invoices"> | ||
<field name="category_id" ref="base.module_category_hidden"/> | ||
<field name="name">Allow pay now on customer invoices</field> | ||
</record> | ||
<record model="res.groups" id="group_pay_now_vendor_invoices"> | ||
<field name="category_id" ref="base.module_category_hidden"/> | ||
<field name="name">Allow pay now on vendor invoices</field> | ||
</record> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<odoo> | ||
<record id="view_move_form" model="ir.ui.view"> | ||
<field name="name">account.move</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form"/> | ||
<field name="arch" type="xml"> | ||
<group id="header_left_group"> | ||
<!-- only allow pay now if manual method available --> | ||
<field name="pay_now_journal_id" readonly="state != 'draft'" invisible="move_type not in ('in_invoice', 'in_refund')" options="{'no_create': True}" | ||
domain="[('company_id', '=', company_id), ('type', 'in', ['bank', 'cash']), ('outbound_payment_method_line_ids.payment_method_id.code', '=', 'manual')]" | ||
groups="account_payment_pro.group_pay_now_vendor_invoices"/> | ||
<field name="pay_now_journal_id" readonly="state != 'draft'" invisible="move_type not in ('out_invoice', 'out_refund')" options="{'no_create': True}" | ||
domain="[('company_id', '=', company_id), ('type', 'in', ['bank', 'cash']), ('inbound_payment_method_line_ids.payment_method_id.code', '=', 'manual')]" | ||
groups="account_payment_pro.group_pay_now_customer_invoices"/> | ||
</group> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters