diff --git a/account_factoring_receivable_balance/models/subrogation_receipt.py b/account_factoring_receivable_balance/models/subrogation_receipt.py index 164dd3b..ec27b70 100644 --- a/account_factoring_receivable_balance/models/subrogation_receipt.py +++ b/account_factoring_receivable_balance/models/subrogation_receipt.py @@ -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) diff --git a/account_factoring_receivable_balance_eurofactor/models/account_journal.py b/account_factoring_receivable_balance_eurofactor/models/account_journal.py index 7503ce5..43c7931 100644 --- a/account_factoring_receivable_balance_eurofactor/models/account_journal.py +++ b/account_factoring_receivable_balance_eurofactor/models/account_journal.py @@ -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): diff --git a/account_factoring_receivable_balance_eurofactor/models/account_move.py b/account_factoring_receivable_balance_eurofactor/models/account_move.py index 19220fc..0254719 100644 --- a/account_factoring_receivable_balance_eurofactor/models/account_move.py +++ b/account_factoring_receivable_balance_eurofactor/models/account_move.py @@ -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") + ) diff --git a/account_factoring_receivable_balance_eurofactor/models/company.py b/account_factoring_receivable_balance_eurofactor/models/company.py index c471231..8985b70 100644 --- a/account_factoring_receivable_balance_eurofactor/models/company.py +++ b/account_factoring_receivable_balance_eurofactor/models/company.py @@ -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) diff --git a/account_factoring_receivable_balance_eurofactor/models/subrogation_receipt.py b/account_factoring_receivable_balance_eurofactor/models/subrogation_receipt.py index 022b515..8ca2838 100644 --- a/account_factoring_receivable_balance_eurofactor/models/subrogation_receipt.py +++ b/account_factoring_receivable_balance_eurofactor/models/subrogation_receipt.py @@ -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 @@ -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} N° {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} N° {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): diff --git a/account_factoring_receivable_balance_eurofactor/views/account_journal.xml b/account_factoring_receivable_balance_eurofactor/views/account_journal.xml index 3807c03..f434bec 100644 --- a/account_factoring_receivable_balance_eurofactor/views/account_journal.xml +++ b/account_factoring_receivable_balance_eurofactor/views/account_journal.xml @@ -13,6 +13,24 @@ + + + + + + + + +