Skip to content

Commit

Permalink
[MIG] account_banking_fr_lcr: migrate to v18
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Jan 30, 2025
1 parent 38e060a commit 1dddb3d
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 122 deletions.
3 changes: 1 addition & 2 deletions account_banking_fr_lcr/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
"external_dependencies": {"python": ["unidecode", "pypdf>=3.1.0"]},
"data": [
"data/account_payment_method.xml",
"views/account_payment_mode.xml",
"views/account_payment_method_line.xml",
"views/account_payment_order.xml",
"views/account_move.xml",
],
"demo": ["demo/lcr_demo.xml"],
"post_init_hook": "lcr_set_unece",
"installable": True,
}
10 changes: 0 additions & 10 deletions account_banking_fr_lcr/demo/lcr_demo.xml

This file was deleted.

2 changes: 1 addition & 1 deletion account_banking_fr_lcr/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import account_payment_method
from . import account_payment_mode
from . import account_payment_method_line
from . import account_payment_order
from . import account_payment_line
from . import account_payment
Expand Down
17 changes: 8 additions & 9 deletions account_banking_fr_lcr/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
class AccountMove(models.Model):
_inherit = "account.move"

payment_mode_fr_lcr_type = fields.Selection(
related="payment_mode_id.fr_lcr_type", store=True
payment_method_line_fr_lcr_type = fields.Selection(
related="preferred_payment_method_line_id.fr_lcr_type", store=True
)
fr_lcr_attachment_id = fields.Many2one(
"ir.attachment", string="Bill of Exchange Attachment"
Expand All @@ -42,8 +42,7 @@ class AccountMove(models.Model):
"res.partner.bank",
compute="_compute_fr_lcr_partner_bank_id",
store=True,
precompute=True,
states={"draft": [("readonly", False)]},
readonly=False,
string="Bill of Exchange Bank Account",
help="Bank account of the customer that will be debited by "
"the bill of exchange. By default, Odoo selects the first French "
Expand All @@ -53,7 +52,7 @@ class AccountMove(models.Model):
domain="[('partner_id', '=', commercial_partner_id)]",
)

@api.depends("partner_id", "payment_mode_id")
@api.depends("partner_id", "preferred_payment_method_line_id")
def _compute_fr_lcr_partner_bank_id(self):
for move in self:
partner_bank_id = False
Expand Down Expand Up @@ -84,16 +83,16 @@ def _post(self, soft=True):
# not for promissory note (we may only know the bank account when
# receiving it)
if (
move.payment_mode_fr_lcr_type in ("accepted", "not_accepted")
move.payment_method_line_fr_lcr_type in ("accepted", "not_accepted")
and not move.fr_lcr_partner_bank_id
):
raise UserError(
_(
"Customer invoice '%(move)s' is configured with "
"payment mode '%(payment_mode)s' which require "
"payment mode '%(payment_method_line)s' which require "
"a bill of exchange bank account.",
move=move.display_name,
payment_mode=move.payment_mode_id.display_name,
payment_method_line=move.preferred_payment_method_line_id.display_name,
)
)
if move.fr_lcr_partner_bank_id:
Expand All @@ -105,7 +104,7 @@ def fr_lcr_print(self):
assert self.state == "posted"
assert self.move_type == "out_invoice"
assert self.payment_method_code == "fr_lcr"
assert self.payment_mode_fr_lcr_type == "accepted"
assert self.payment_method_line_fr_lcr_type == "accepted"
if self.fr_lcr_attachment_id and self.payment_state not in (
"in_payment",
"paid",
Expand Down
2 changes: 1 addition & 1 deletion account_banking_fr_lcr/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _prepare_cfonb_line(self, transactions_count):
)
else:
nom_banque = " " * 24
code_acceptation = LCR_TYPE_CODES[order.payment_mode_id.fr_lcr_type]
code_acceptation = LCR_TYPE_CODES[order.payment_method_line_id.fr_lcr_type]
montant_centimes = str(round(self.amount * 100))
zero_montant_centimes = montant_centimes.zfill(12)
if payment_line.move_line_id and payment_line.move_line_id.move_id.invoice_date:
Expand Down
2 changes: 1 addition & 1 deletion account_banking_fr_lcr/models/account_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _compute_payment_line(self):
res = super()._compute_payment_line()
for line in self:
if (
line.order_id.payment_mode_id.payment_method_id.code == "fr_lcr"
line.order_id.payment_method_line_id.payment_method_id.code == "fr_lcr"
and line.move_line_id
and line.move_line_id.move_id.fr_lcr_partner_bank_id
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from odoo.exceptions import ValidationError


class AccountPaymentMode(models.Model):
_inherit = "account.payment.mode"
class AccountPaymentMethodLine(models.Model):
_inherit = "account.payment.method.line"

fr_lcr_type = fields.Selection(
[
Expand Down Expand Up @@ -71,24 +71,24 @@ def _fr_lcr_dailly_option_selection(self):

@api.depends("payment_method_id")
def _compute_fr_lcr_type(self):
for mode in self:
for line in self:
fr_lcr_type = False
if mode.payment_method_id and mode.payment_method_id.code == "fr_lcr":
if line.payment_method_id and line.payment_method_id.code == "fr_lcr":
fr_lcr_type = "not_accepted"
mode.fr_lcr_type = fr_lcr_type
line.fr_lcr_type = fr_lcr_type

@api.constrains("payment_method_id", "fr_lcr_type")
def _check_fr_lcr(self):
for mode in self:
for line in self:
if (
mode.payment_method_id
and mode.payment_method_id.code == "fr_lcr"
and not mode.fr_lcr_type
line.payment_method_id
and line.payment_method_id.code == "fr_lcr"
and not line.fr_lcr_type
):
raise ValidationError(
_(
"The field 'Bill of Exchange Type' must be set on "
"payment mode '%s'."
)
% mode.display_name
% line.display_name
)
28 changes: 15 additions & 13 deletions account_banking_fr_lcr/models/account_payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class AccountPaymentOrder(models.Model):

fr_lcr_collection_option = fields.Selection(
lambda self: self.env[
"account.payment.mode"
"account.payment.method.line"
]._fr_lcr_collection_option_selection(),
compute="_compute_fr_lcr_fields",
store=True,
precompute=True,
states={"draft": [("readonly", False)]},
readonly=False,
string="Collection Option",
)
# if fr_lcr_value_date is also used for Dailly, we'll have to change
Expand All @@ -62,25 +62,27 @@ class AccountPaymentOrder(models.Model):
precompute=True,
)
fr_lcr_dailly_option = fields.Selection(
lambda self: self.env["account.payment.mode"]._fr_lcr_dailly_option_selection(),
lambda self: self.env[
"account.payment.method.line"
]._fr_lcr_dailly_option_selection(),
compute="_compute_fr_lcr_fields",
store=True,
precompute=True,
states={"draft": [("readonly", False)]},
readonly=False,
string="Dailly Option",
)

@api.depends("payment_mode_id")
@api.depends("payment_method_line_id")
def _compute_fr_lcr_fields(self):
for order in self:
fr_lcr_collection_option = False
fr_lcr_dailly = False
fr_lcr_dailly_option = False
if order.payment_mode_id.payment_method_id.code == "fr_lcr":
mode = order.payment_mode_id
fr_lcr_collection_option = mode.fr_lcr_default_collection_option
fr_lcr_dailly = mode.fr_lcr_dailly
fr_lcr_dailly_option = mode.fr_lcr_default_dailly_option
if order.payment_method_line_id.payment_method_id.code == "fr_lcr":
method_line = order.payment_method_line_id
fr_lcr_collection_option = method_line.fr_lcr_default_collection_option
fr_lcr_dailly = method_line.fr_lcr_dailly
fr_lcr_dailly_option = method_line.fr_lcr_default_dailly_option
order.fr_lcr_collection_option = fr_lcr_collection_option
order.fr_lcr_dailly = fr_lcr_dailly
order.fr_lcr_dailly_option = fr_lcr_dailly_option
Expand Down Expand Up @@ -178,10 +180,10 @@ def _prepare_first_cfonb_line(self):
code_operation = "60"
numero_enregistrement = "00000001"
numero_emetteur = "000000" # It is not needed for LCR
if self.payment_mode_id.fr_lcr_convention_type:
if self.payment_method_line_id.fr_lcr_convention_type:
type_convention = self._prepare_lcr_field(
"Type de convention",
self.payment_mode_id.fr_lcr_convention_type,
self.payment_method_line_id.fr_lcr_convention_type,
6,
)
else:
Expand Down Expand Up @@ -291,7 +293,7 @@ def generate_payment_file(self):
cfonb_lines.append(
self._prepare_final_cfonb_line(total_amount, transactions_count)
)
if self.payment_mode_id.fr_lcr_type == "promissory_note":
if self.payment_method_line_id.fr_lcr_type == "promissory_note":
file_prefix = "BOR"
else:
file_prefix = "LCR"
Expand Down
5 changes: 1 addition & 4 deletions account_banking_fr_lcr/post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, api


def lcr_set_unece(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
def lcr_set_unece(env):
lcr = env.ref("account_banking_fr_lcr.fr_lcr")
if lcr:
# This module doesn't depend on account_payment_unece
Expand Down
Loading

0 comments on commit 1dddb3d

Please sign in to comment.