Skip to content

Commit

Permalink
IMP eurofactor: add export account
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Nov 19, 2024
1 parent f68d2fe commit 88df9c2
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ def action_post(self):
for rec in self:
if (
rec.state == "confirmed"
and rec.holdback_amount > 0
and rec.expense_untaxed_amount > 0
and rec.expense_tax_amount > 0
# previously holdback_amount, expense_untaxed_amount,
# expense_untaxed_amount fields should be > 0
# useless
):
vals_list = self._prepare_journal_entry_vals_list()
res = rec.env["account.move"].create(vals_list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ class AccountJournal(models.Model):
help="A saisir dans ce champ des clés / valeurs séparées par des =",
)
factor_settings = fields.Char(compute="_compute_factor_settings")
factoring_current_acc_exp_id = fields.Many2one(
comodel_name="account.account",
string="Current Account export",
tracking=True,
)
factoring_holdback_acc_exp_id = fields.Many2one(
comodel_name="account.account",
string="Holdback Account export",
tracking=True,
)
factoring_pending_recharging_acc_exp_id = fields.Many2one(
comodel_name="account.account",
string="Pending Recharging Account export",
tracking=True,
)

@api.depends("factor_data")
def _compute_factor_settings(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ def _eurof_fields_rpt(self):
"Origine": self.move_id.invoice_origin,
"Devise": self.currency_id.name,
}

def _eurof_market(self, export=False):
if export:
return self.filtered(
lambda s: s.move_id.commercial_partner_id.country_id
== self.env.ref("base.fr")
)
return self.filtered(
lambda s: s.move_id.commercial_partner_id.country_id
!= self.env.ref("base.fr")
)
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ def _configure_eurof_factoring(self):
acc = {}
suffix = self._get_factor_shortname()
for acco in (
["4115", "Factoring Receivable", "income"],
["4671", "Factoring Current", "income"],
["4672", "Factoring Holdback", "income"],
["4673", "Factoring Recharging", "income"],
["4115", "Factoring Receivable", "income", suffix],
["4671", "Factoring Current", "income", suffix],
["4672", "Factoring Holdback", "income", suffix],
["4673", "Factoring Recharging", "income", suffix],
["4671", "Factoring Current exp", "income", "CE"],
["4672", "Factoring Holdback exp", "income", "CE"],
["4673", "Factoring Recharging exp", "income", "CE"],
):
code = f"{acco[0]}{suffix}"
code = f"{acco[0]}{acco[3]}"
values = {"code": code, "name": acco[1], "account_type": acco[2]}
values.update(vals)
acc[code] = self.env["account.account"].create(values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import inspect
import re

from odoo import Command, fields, models
from odoo import Command, _, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.safe_eval import safe_eval

Expand All @@ -24,36 +24,82 @@ def _prepare_journal_entry_vals_list(self):
self.ensure_one()
fact_journal = self.factor_journal_id
vals_list = super()._prepare_journal_entry_vals_list()
lines = [
fr_lines, export_lines = []
if (
not fact_journal.factoring_holdback_acc_exp_id
or not fact_journal.factoring_holdback_acc_exp_id
):
raise ValidationError(_("Missing export account on factor journal"))

def get_current_account_lines(move_lines, account_field):
return [
Command.create(
{
"date": fields.date.today(),
"account_id": fact_journal[account_field].id,
"name": x.name,
"debit": x.credit,
"credit": x.debit,
}
)
for x in self.line_ids
]

fr_lines.append(
get_current_account_lines(
self.line_ids._eurof_market(), "factoring_current_account_id"
)
)
export_lines.append(
get_current_account_lines(
self.line_ids._eurof_market(export=True), "factoring_current_acc_exp_id"
)
)
name = f"{self.display_name}{self.id}"
fr_lines.append(
Command.create(
{
"date": fields.date.today(),
"account_id": fact_journal.factoring_current_account_id.id,
"name": x.name,
"debit": x.credit,
"credit": x.debit,
"account_id": fact_journal.factoring_holdback_account_id.id,
"name": f"total {name}",
"debit": sum(self.line_ids._eurof_market().mapped("debit")),
"credit": sum(self.line_ids._eurof_market().mapped("credit")),
}
)
for x in self.line_ids
]
name = f"{self.display_name}{self.id}"
line = {
)
export_lines.append(
Command.create(
{
"date": fields.date.today(),
"account_id": fact_journal.factoring_holdback_acc_exp_id.id,
"name": f"total {name}",
"debit": sum(
self.line_ids._eurof_market(export=True).mapped("debit")
),
"credit": sum(
self.line_ids._eurof_market(export=True).mapped("credit")
),
}
)
)
fr_vals = {
"journal_id": fact_journal.id,
"subrogation_id": self.id,
"company_id": self.company_id.id,
"date": fields.date.today(),
"account_id": fact_journal.factoring_holdback_account_id.id,
"name": f"total {name}",
"debit": sum(self.line_ids.mapped("debit")),
"credit": sum(self.line_ids.mapped("credit")),
"ref": f"Contrepartie {name} domestique",
"line_ids": fr_lines,
}
lines.append(Command.create(line))
vals = {
export_vals = {
"journal_id": fact_journal.id,
"subrogation_id": self.id,
"company_id": self.company_id.id,
"date": fields.date.today(),
"ref": f"Contrepartie {name}",
"line_ids": lines,
"ref": f"Contrepartie {name} export",
"line_ids": export_lines,
}
vals_list.append(vals)
vals_list.append(fr_vals)
vals_list.append(export_vals)
return vals_list

def _prepare_factor_file_eurof(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
<field name="factor_data" />
<field name="factor_settings" />
</xpath>
<xpath
expr="//field[@name='factoring_current_account_id']"
position="after"
>
<field name="factoring_current_acc_exp_id" />
</xpath>
<xpath
expr="//field[@name='factoring_holdback_account_id']"
position="after"
>
<field name="factoring_holdback_acc_exp_id" />
</xpath>
<xpath
expr="//field[@name='factoring_pending_recharging_account_id']"
position="after"
>
<field name="factoring_pending_recharging_acc_exp_id" />
</xpath>
</field>
</record>

Expand Down

0 comments on commit 88df9c2

Please sign in to comment.