diff --git a/account_factoring_receivable_balance/__manifest__.py b/account_factoring_receivable_balance/__manifest__.py index 4725360cd7..35fa733cdc 100644 --- a/account_factoring_receivable_balance/__manifest__.py +++ b/account_factoring_receivable_balance/__manifest__.py @@ -19,11 +19,7 @@ "security/ir.model.access.csv", "security/misc.xml", "views/account_journal.xml", - "views/company.xml", "views/partner.xml", "views/subrogation_receipt.xml", ], - "demo": [ - "views/company_demo.xml", - ], } diff --git a/account_factoring_receivable_balance/models/__init__.py b/account_factoring_receivable_balance/models/__init__.py index 84aacb09bb..be098f00bf 100644 --- a/account_factoring_receivable_balance/models/__init__.py +++ b/account_factoring_receivable_balance/models/__init__.py @@ -1,4 +1,4 @@ -from . import company from . import account_journal from . import account_move +from . import res_partner from . import subrogation_receipt diff --git a/account_factoring_receivable_balance/models/account_journal.py b/account_factoring_receivable_balance/models/account_journal.py index 510155f08a..6b900f5187 100644 --- a/account_factoring_receivable_balance/models/account_journal.py +++ b/account_factoring_receivable_balance/models/account_journal.py @@ -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" ) diff --git a/account_factoring_receivable_balance/models/company.py b/account_factoring_receivable_balance/models/company.py deleted file mode 100644 index 5d353dcacc..0000000000 --- a/account_factoring_receivable_balance/models/company.py +++ /dev/null @@ -1,56 +0,0 @@ -# © 2022 David BEAL @ Akretion -# © 2022 Alexis DE LATTRE @ Akretion -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import Command, _, api, fields, models -from odoo.exceptions import UserError -from odoo.tests.common import Form - - -class ResCompany(models.Model): - _inherit = "res.company" - - factor_config_currency_id = fields.Many2one( - comodel_name="res.currency", - string="Facto Currency", - help="Use to configure account and journal", - ) - - @api.model - def _create_french_company(self, company_name=None): - "Can be called from Odoo Shell" - demo_cpny_name = "BPCE demo" - previous_cpny = self.search([("name", "=", demo_cpny_name)], limit=1) - previous_cpny.write({"name": "Company %s" % previous_cpny.id}) - company = self.create( - { - "name": company_name or demo_cpny_name, - "street": "42 rue du logiciel libre", - "zip": "69009", - "city": "Lyon", - "country_id": self.env.ref("base.fr").id, - "siret": "77788899100018", - "vat": "FR51777888991", - } - ) - self.env.ref("l10n_fr.l10n_fr_pcg_chart_template")._load(20.0, 20.0, company) - self.env.ref("base.user_admin").company_ids = [Command.link(company.id)] - return company - - def _prepare_data_for_factor(self, move_type="out_invoice"): - self.ensure_one() - move_form = Form( - self.env["account.move"] - .with_company(self.env.company) - .with_context( - default_move_type=move_type, - account_predictive_bills_disable_prediction=True, - ) - ) - move_form.invoice_date = fields.Date.from_string("2022-10-03") - move_form.date = move_form.invoice_date - move_form.partner_id = self.env.ref("base.res_partner_2") - - def ui_populate_data_for_factor(self): - raise UserError(_("Not yet implemented")) - # self._prepare_data_for_factor() diff --git a/account_factoring_receivable_balance/models/res_partner.py b/account_factoring_receivable_balance/models/res_partner.py new file mode 100644 index 0000000000..098bf9be7e --- /dev/null +++ b/account_factoring_receivable_balance/models/res_partner.py @@ -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.", + ) diff --git a/account_factoring_receivable_balance/models/subrogation_receipt.py b/account_factoring_receivable_balance/models/subrogation_receipt.py index 07988ec894..dc18928364 100644 --- a/account_factoring_receivable_balance/models/subrogation_receipt.py +++ b/account_factoring_receivable_balance/models/subrogation_receipt.py @@ -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 @@ -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 @@ -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}) diff --git a/account_factoring_receivable_balance/views/account_journal.xml b/account_factoring_receivable_balance/views/account_journal.xml index f92a570a16..a56054ffc7 100644 --- a/account_factoring_receivable_balance/views/account_journal.xml +++ b/account_factoring_receivable_balance/views/account_journal.xml @@ -21,11 +21,13 @@ + + diff --git a/account_factoring_receivable_balance/views/company.xml b/account_factoring_receivable_balance/views/company.xml deleted file mode 100644 index 68ad8f1ac0..0000000000 --- a/account_factoring_receivable_balance/views/company.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - res.company - - - - - - - - - - - - - - - - - diff --git a/account_factoring_receivable_balance/views/company_demo.xml b/account_factoring_receivable_balance/views/company_demo.xml deleted file mode 100644 index e1a98a4db4..0000000000 --- a/account_factoring_receivable_balance/views/company_demo.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - res.company - - - - -