-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: added feature of lines con account.payment.register
- Loading branch information
1 parent
d28447a
commit c5f5f31
Showing
9 changed files
with
400 additions
and
131 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
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,3 @@ | ||
from . import counterpart_line | ||
from . import account_payment | ||
from . import account_move |
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,154 @@ | ||
# Copyright 2022 ForgeFlow, S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
dict_payment_type = dict( | ||
inbound=["out_invoice", "out_refund", "out_receipt"], | ||
outbound=["in_invoice", "in_refund", "in_receipt"], | ||
) | ||
|
||
|
||
class AccountPaymentCounterLinesAbstract(models.AbstractModel): | ||
_name = "account.payment.counterpart.line.abstract" | ||
_description = "Counterpart line payment Abstract" | ||
|
||
company_id = fields.Many2one( | ||
comodel_name="res.company", compute="_compute_company_fields" | ||
) | ||
name = fields.Char(string="Description", required=True, default="/") | ||
account_id = fields.Many2one( | ||
"account.account", | ||
string="Account", | ||
required=True, | ||
ondelete="restrict", | ||
check_company=True, | ||
) | ||
analytic_account_id = fields.Many2one( | ||
comodel_name="account.analytic.account", | ||
string="Analytic Account", | ||
ondelete="restrict", | ||
check_company=True, | ||
) | ||
currency_id = fields.Many2one( | ||
comodel_name="res.currency", | ||
string="Currency", | ||
compute="_compute_company_fields", | ||
) | ||
|
||
def _compute_company_fields(self): | ||
for rec in self: | ||
rec.company_id = self.env.company.id | ||
rec.currency_id = self.env.company.currency_id.id | ||
|
||
amount = fields.Monetary(string="Amount", required=True) | ||
amount_currency = fields.Monetary( | ||
string="Amount in Company Currency", compute="_compute_amounts" | ||
) | ||
aml_amount_residual = fields.Monetary( | ||
string="Amount Residual", | ||
compute="_compute_amounts", | ||
) | ||
residual_after_payment = fields.Monetary( | ||
compute="_compute_amounts", | ||
) | ||
aml_amount_residual_currency = fields.Monetary( | ||
string="Amount Residual Currency", | ||
compute="_compute_amounts", | ||
) | ||
residual_after_payment_currency = fields.Monetary( | ||
compute="_compute_amounts", | ||
) | ||
|
||
def _get_onchange_fields(self): | ||
return "aml_id.amount_residual", "amount" | ||
|
||
@api.depends(lambda x: x._get_onchange_fields()) | ||
def _compute_amounts(self): | ||
for rec in self: | ||
payment_date = ( | ||
hasattr(rec.payment_id, "payment_date") | ||
and rec.payment_id.payment_date | ||
or rec.payment_id.date | ||
) | ||
rec.amount_currency = rec.payment_id.currency_id._convert( | ||
rec.amount, | ||
rec.payment_id.company_id.currency_id, | ||
rec.payment_id.company_id, | ||
date=payment_date, | ||
) | ||
rec.aml_amount_residual = rec.aml_id.amount_residual | ||
rec.residual_after_payment = max( | ||
abs(rec.aml_id.amount_residual) - rec.amount_currency, 0 | ||
) | ||
rec.aml_amount_residual_currency = rec.aml_id.amount_residual_currency | ||
rec.residual_after_payment_currency = max( | ||
abs(rec.aml_id.amount_residual_currency) - rec.amount_currency, 0 | ||
) | ||
|
||
partner_id = fields.Many2one("res.partner", string="Partner", ondelete="restrict") | ||
commercial_partner_id = fields.Many2one(related="partner_id.commercial_partner_id") | ||
move_id = fields.Many2one( | ||
"account.move", string="Journal Entry", ondelete="set null" | ||
) | ||
move_ids = fields.One2many( | ||
"account.move.line", | ||
"payment_line_id", | ||
string="Journal Entries Created", | ||
) | ||
aml_id = fields.Many2one( | ||
"account.move.line", string="Journal Item to Reconcile", ondelete="set null" | ||
) | ||
aml_date_maturity = fields.Date( | ||
string="Date Maturity", required=False, related="aml_id.date_maturity" | ||
) | ||
|
||
@api.onchange("move_id", "aml_id") | ||
def _onchange_move_id(self): | ||
aml_model = self.env["account.move.line"] | ||
for rec in self: | ||
type_move = dict_payment_type.get(rec.payment_id.payment_type, []) | ||
if rec.move_id and not rec.aml_id: | ||
domain = [ | ||
("move_id", "=", rec.move_id.id), | ||
("amount_residual", "!=", 0.0), | ||
] | ||
lines_ordered = aml_model.search( | ||
domain, order="date_maturity ASC", limit=1 | ||
) | ||
if lines_ordered: | ||
rec.aml_id = lines_ordered.id | ||
if rec.aml_id: | ||
rec.move_id = rec.aml_id.move_id.id | ||
rec.account_id = rec.aml_id.account_id.id | ||
rec.amount = abs(rec.aml_id.amount_residual) | ||
rec.partner_id = rec.aml_id.partner_id.id | ||
if rec.move_id.move_type == "entry": | ||
if rec.payment_id.partner_type == "supplier": | ||
if rec.payment_id.payment_type == "outbound": | ||
rec.amount = -rec.aml_id.amount_residual | ||
else: | ||
rec.amount = rec.aml_id.amount_residual | ||
else: | ||
if rec.payment_id.payment_type == "outbound": | ||
rec.amount = -rec.aml_id.amount_residual | ||
else: | ||
rec.amount = rec.aml_id.amount_residual | ||
else: | ||
if ( | ||
type_move | ||
and rec.move_id.move_type not in type_move | ||
and rec.amount | ||
): | ||
rec.amount *= -1 | ||
|
||
@api.constrains("amount", "aml_amount_residual") | ||
def constrains_amount_residual(self): | ||
for rec in self: | ||
if rec.aml_id and 0 < rec.aml_amount_residual < rec.amount: | ||
raise ValidationError( | ||
_( | ||
"the amount exceeds the residual amount, please check the invoice %s" | ||
), | ||
(rec.aml_id.move_id.name or rec.aml_id.name), | ||
) |
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 @@ | ||
from . import account_payment_register |
Oops, something went wrong.