Skip to content

Commit

Permalink
[REF] account_factoring_receivable_balance: Factor configs moved to J…
Browse files Browse the repository at this point in the history
…ournal
  • Loading branch information
dreispt committed Jun 7, 2024
1 parent 3234d44 commit 60c5c15
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 76 deletions.
2 changes: 1 addition & 1 deletion account_factoring_receivable_balance/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import company
from . import account_journal
from . import account_move
from . import res_partner
from . import subrogation_receipt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class AccountJournal(models.Model):
_inherit = "account.journal"

factor_type = fields.Selection(string="Factor", selection=[("", "")])
factor_code = fields.Char(help="Account Number for factor company")
factor_start_date = fields.Date(
tracking=True,
help="No account move will be selected before this date",
)
factoring_receivable_account_id = fields.Many2one(
comodel_name="account.account", string="Receivable Account"
)
Expand Down
56 changes: 0 additions & 56 deletions account_factoring_receivable_balance/models/company.py

This file was deleted.

13 changes: 13 additions & 0 deletions account_factoring_receivable_balance/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# © 2024 Open Source Integrators, Daniel Reis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class Partner(models.Model):
_inherit = "res.partner"

factor_journal_id = fields.Many2one(
comodel_name="account.journal",
help="Select the factoring service for this partner.",
)
27 changes: 9 additions & 18 deletions account_factoring_receivable_balance/models/subrogation_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,9 @@ def _compute_display_name(self):
)

@api.model
def _get_domain_for_factor(
self, factor_type, partner_selection_field=None, currency=None
):
"""partner_selection_field is a field on partners to guess
which account data need to be retrieved.
You have to create it in your own factor module
Query example for debugging purpose:
def _get_domain_for_factor(self, factor_type, factor_journal, currency=None):
"""
Query example for debugging purpose: # FIXME
SELECT l.id, l.name, l.date, l.create_date, l.debit, p2.name, s.target_date
, l.partner_id, o.res_id, l.subrogation_id
Expand All @@ -131,14 +126,15 @@ def _get_domain_for_factor(
self._get_customer_accounts(),
("full_reconcile_id", "=", False),
(
"partner_id.commercial_partner_id.%s" % partner_selection_field,
"=",
True,
"partner_id.commercial_partner_id.factor_journal_id" "=",
factor_journal.id,
),
"|",
("move_id.partner_bank_id", "=", bank_journal.bank_account_id.id),
("move_id.partner_bank_id", "=", False),
]
if factor_journal.factor_start_date:
domain.append([("date", ">=", factor_journal.factor_start_date)])
return domain

@api.model
Expand All @@ -165,17 +161,12 @@ def _get_customer_accounts(self):
"%s%s" % (account.code.replace("0", ""), "%"), # noqa: UP031
)

def _get_partner_field(self):
"Inherit to define your own fields depending of your factor module"
self.ensure_one()
return None

def action_compute_lines(self):
self.ensure_one()
journal = self.factor_journal_id
domain = self._get_domain_for_factor(
self.factor_type,
partner_selection_field=self._get_partner_field(),
self.factor_type, # TODO: this is a redundant argument!
self.factor_journal_id,
currency=journal.currency_id,
)
self.line_ids.write({"subrogation_id": False})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
<page name="factor" string="Factor" invisible="not factor_type">
<group name="receivable_balance" string="Receiveable Balance">
<group name="balance_left">
<field name="factor_code" />
<field name="factoring_receivable_account_id" />
<field name="factoring_current_account_id" />
<field name="factoring_holdback_account_id" />
</group>
<group name="balance_right">
<field name="factor_start_date" />
<field name="factoring_pending_recharging_account_id" />
<field name="factoring_expense_account_id" />
</group>
Expand Down
4 changes: 3 additions & 1 deletion account_factoring_receivable_balance/views/partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
name="factoring"
string="Factoring"
groups="account.group_account_invoice"
/>
>
<field name="factor_journal_id" />
</group>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 60c5c15

Please sign in to comment.