Compare commits
7 Commits
474485f963
...
8eb4b8dc6c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8eb4b8dc6c | ||
|
|
d0a912b1da | ||
|
|
8ef88da94a | ||
|
|
38a2684782 | ||
|
|
2ec90a50b0 | ||
|
|
4ee261e189 | ||
|
|
ab3fcc56db |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
'name': 'Fusion Accounting Follow-up',
|
||||
'version': '19.0.1.0.23',
|
||||
'version': '19.0.1.0.28',
|
||||
'category': 'Accounting/Accounting',
|
||||
'summary': 'AI-augmented customer follow-ups (dunning) for unpaid invoices.',
|
||||
'description': """
|
||||
@@ -28,12 +28,17 @@ menu hides; the engine + AI tools remain available for the chat.
|
||||
'depends': [
|
||||
'fusion_accounting_core',
|
||||
'fusion_accounting_ai',
|
||||
'fusion_accounting_migration',
|
||||
'account',
|
||||
'mail',
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'data/cron.xml',
|
||||
'data/followup_levels_data.xml',
|
||||
'data/mail_templates_data.xml',
|
||||
'wizards/batch_followup_wizard_views.xml',
|
||||
'views/menu_views.xml',
|
||||
],
|
||||
'assets': {
|
||||
'web.assets_backend': [
|
||||
|
||||
32
fusion_accounting_followup/data/followup_levels_data.xml
Normal file
32
fusion_accounting_followup/data/followup_levels_data.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="level_reminder" model="fusion.followup.level">
|
||||
<field name="name">Friendly Reminder</field>
|
||||
<field name="sequence">1</field>
|
||||
<field name="delay_days">7</field>
|
||||
<field name="tone">gentle</field>
|
||||
<field name="description">First contact - friendly reminder of overdue invoice.</field>
|
||||
<field name="active" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record id="level_warning" model="fusion.followup.level">
|
||||
<field name="name">Firm Warning</field>
|
||||
<field name="sequence">2</field>
|
||||
<field name="delay_days">30</field>
|
||||
<field name="tone">firm</field>
|
||||
<field name="description">Second contact - clear request for immediate action.</field>
|
||||
<field name="active" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record id="level_legal_notice" model="fusion.followup.level">
|
||||
<field name="name">Legal Notice</field>
|
||||
<field name="sequence">3</field>
|
||||
<field name="delay_days">60</field>
|
||||
<field name="tone">legal</field>
|
||||
<field name="description">Final notice before referring to collections.</field>
|
||||
<field name="requires_manual_review" eval="True"/>
|
||||
<field name="active" eval="True"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
85
fusion_accounting_followup/data/mail_templates_data.xml
Normal file
85
fusion_accounting_followup/data/mail_templates_data.xml
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="email_template_followup_gentle" model="mail.template">
|
||||
<field name="name">Fusion Followup: Friendly Reminder</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="subject">Friendly reminder: invoice payment</field>
|
||||
<field name="email_from">{{ user.email_formatted }}</field>
|
||||
<field name="email_to">{{ object.email }}</field>
|
||||
<field name="body_html" type="html">
|
||||
<div>
|
||||
<p>Dear <t t-out="object.name"/>,</p>
|
||||
<p>This is a friendly reminder that you have outstanding invoices on
|
||||
your account. We understand that things happen — please let us know
|
||||
if there is anything we can do to help resolve this.</p>
|
||||
<p>You can review your account statement at any time, or contact our
|
||||
accounts receivable team with any questions.</p>
|
||||
<p>Best regards,<br/>
|
||||
<t t-out="user.company_id.name"/></p>
|
||||
</div>
|
||||
</field>
|
||||
<field name="lang">{{ object.lang }}</field>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record id="email_template_followup_firm" model="mail.template">
|
||||
<field name="name">Fusion Followup: Firm Warning</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="subject">Outstanding invoices — action required</field>
|
||||
<field name="email_from">{{ user.email_formatted }}</field>
|
||||
<field name="email_to">{{ object.email }}</field>
|
||||
<field name="body_html" type="html">
|
||||
<div>
|
||||
<p>Dear <t t-out="object.name"/>,</p>
|
||||
<p>Our records show outstanding invoices that require your immediate
|
||||
attention. We request that you remit payment as soon as possible to
|
||||
avoid further escalation.</p>
|
||||
<p>If you have already remitted payment, please disregard this notice
|
||||
and contact us with the payment details so we can update our records.</p>
|
||||
<p>If there are any disputes or concerns regarding these invoices,
|
||||
please contact our accounts receivable team immediately.</p>
|
||||
<p>Regards,<br/>
|
||||
<t t-out="user.company_id.name"/></p>
|
||||
</div>
|
||||
</field>
|
||||
<field name="lang">{{ object.lang }}</field>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<record id="email_template_followup_legal" model="mail.template">
|
||||
<field name="name">Fusion Followup: Legal Notice</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="subject">FINAL NOTICE — outstanding balance</field>
|
||||
<field name="email_from">{{ user.email_formatted }}</field>
|
||||
<field name="email_to">{{ object.email }}</field>
|
||||
<field name="body_html" type="html">
|
||||
<div>
|
||||
<p>Dear <t t-out="object.name"/>,</p>
|
||||
<p>This is a FINAL NOTICE regarding outstanding invoices on your
|
||||
account. Despite previous reminders, your balance remains unpaid.</p>
|
||||
<p>If full payment is not received within 7 days from the date of this
|
||||
notice, we will be forced to refer this matter to our legal department
|
||||
for collection. This may include reporting the delinquency to credit
|
||||
bureaus and pursuing further legal action as permitted by law.</p>
|
||||
<p>Please contact us immediately to resolve this matter.</p>
|
||||
<p>Regards,<br/>
|
||||
<t t-out="user.company_id.name"/></p>
|
||||
</div>
|
||||
</field>
|
||||
<field name="lang">{{ object.lang }}</field>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
</record>
|
||||
|
||||
<!-- Wire templates to default levels -->
|
||||
<record id="level_reminder" model="fusion.followup.level">
|
||||
<field name="mail_template_id" ref="email_template_followup_gentle"/>
|
||||
</record>
|
||||
<record id="level_warning" model="fusion.followup.level">
|
||||
<field name="mail_template_id" ref="email_template_followup_firm"/>
|
||||
</record>
|
||||
<record id="level_legal_notice" model="fusion.followup.level">
|
||||
<field name="mail_template_id" ref="email_template_followup_legal"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -5,3 +5,4 @@ from . import res_partner
|
||||
from . import account_move_line
|
||||
from . import fusion_followup_engine
|
||||
from . import fusion_followup_cron
|
||||
from . import fusion_migration_wizard
|
||||
|
||||
87
fusion_accounting_followup/models/fusion_migration_wizard.py
Normal file
87
fusion_accounting_followup/models/fusion_migration_wizard.py
Normal file
@@ -0,0 +1,87 @@
|
||||
"""Followup-specific migration step.
|
||||
|
||||
Backfills fusion.followup.level from Enterprise's account_followup.followup.line
|
||||
records (if Enterprise account_followup is installed)."""
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FusionMigrationWizard(models.TransientModel):
|
||||
_inherit = "fusion.migration.wizard"
|
||||
|
||||
def _followup_bootstrap_step(self):
|
||||
"""Backfill fusion.followup.level from account_followup.followup.line."""
|
||||
result = {
|
||||
'step': 'followup_bootstrap',
|
||||
'enterprise_module_present': False,
|
||||
'created': 0, 'skipped': 0, 'errors': [],
|
||||
}
|
||||
|
||||
# Enterprise's followup model — name varies by version
|
||||
EnterpriseLine = self.env.get('account_followup.followup.line')
|
||||
if EnterpriseLine is None:
|
||||
EnterpriseLine = self.env.get('account.followup.line')
|
||||
if EnterpriseLine is None:
|
||||
result['enterprise_module_present'] = False
|
||||
return result
|
||||
result['enterprise_module_present'] = True
|
||||
|
||||
FusionLevel = self.env['fusion.followup.level'].sudo()
|
||||
try:
|
||||
ee_records = EnterpriseLine.sudo().search([])
|
||||
except Exception as e:
|
||||
result['errors'].append(f"Enterprise search failed: {e}")
|
||||
return result
|
||||
|
||||
# Pick a starting offset that doesn't clash with anything already in
|
||||
# fusion_followup_level (seeded defaults at 1..3 plus any prior
|
||||
# migration runs). We allocate a unique sequence per Enterprise line
|
||||
# by max(existing) + 1, ensuring idempotency + within-batch uniqueness.
|
||||
existing_max = max(FusionLevel.search([]).mapped('sequence') or [100])
|
||||
next_seq = max(existing_max + 1, 101)
|
||||
|
||||
# Map Enterprise tone-ish fields to ours
|
||||
for ee in ee_records:
|
||||
try:
|
||||
raw_seq = getattr(ee, 'sequence', None) or 50
|
||||
name = getattr(ee, 'name', None) or f"Migrated Level {raw_seq}"
|
||||
# Idempotency: skip if a level with same name was already
|
||||
# backfilled in a prior migration run.
|
||||
existing = FusionLevel.search([('name', '=', name)], limit=1)
|
||||
if existing:
|
||||
result['skipped'] += 1
|
||||
continue
|
||||
|
||||
delay = getattr(ee, 'delay', None) or getattr(ee, 'delay_days', 7)
|
||||
# Enterprise tone heuristic: scale by sequence
|
||||
tone = 'gentle' if raw_seq <= 1 else 'firm' if raw_seq <= 2 else 'legal'
|
||||
|
||||
with self.env.cr.savepoint():
|
||||
FusionLevel.create({
|
||||
'name': name,
|
||||
'sequence': next_seq,
|
||||
'delay_days': delay,
|
||||
'tone': tone,
|
||||
'active': True,
|
||||
})
|
||||
next_seq += 1
|
||||
result['created'] += 1
|
||||
except Exception as e:
|
||||
result['errors'].append(f"Line {ee.id}: {e}")
|
||||
|
||||
_logger.info(
|
||||
"fusion_accounting_followup migration: %d created, %d skipped, %d errors",
|
||||
result['created'], result['skipped'], len(result['errors']))
|
||||
return result
|
||||
|
||||
def action_run_migration(self):
|
||||
result = super().action_run_migration() if hasattr(super(), 'action_run_migration') else None
|
||||
try:
|
||||
self._followup_bootstrap_step()
|
||||
except Exception as e:
|
||||
_logger.warning("followup_bootstrap_step failed: %s", e)
|
||||
return result
|
||||
@@ -5,3 +5,4 @@ access_fusion_followup_run_user,fusion.followup.run.user,model_fusion_followup_r
|
||||
access_fusion_followup_run_admin,fusion.followup.run.admin,model_fusion_followup_run,fusion_accounting_core.group_fusion_accounting_admin,1,1,1,1
|
||||
access_fusion_followup_text_cache_user,fusion.followup.text.cache.user,model_fusion_followup_text_cache,base.group_user,1,0,0,0
|
||||
access_fusion_followup_text_cache_admin,fusion.followup.text.cache.admin,model_fusion_followup_text_cache,fusion_accounting_core.group_fusion_accounting_admin,1,1,1,1
|
||||
access_fusion_batch_followup_wizard_user,fusion.batch.followup.wizard.user,model_fusion_batch_followup_wizard,base.group_user,1,1,1,0
|
||||
|
||||
|
@@ -17,3 +17,6 @@ from . import test_followup_cron
|
||||
from . import test_engine_property
|
||||
from . import test_followup_full_flow
|
||||
from . import test_performance_benchmarks
|
||||
from . import test_batch_followup_wizard
|
||||
from . import test_migration_round_trip
|
||||
from . import test_coexistence
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests import tagged
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestBatchFollowupWizard(TransactionCase):
|
||||
|
||||
def test_default_loads_active_ids(self):
|
||||
partners = self.env['res.partner'].create([
|
||||
{'name': 'B1'}, {'name': 'B2'},
|
||||
])
|
||||
wizard = self.env['fusion.batch.followup.wizard'].with_context(
|
||||
active_model='res.partner', active_ids=partners.ids,
|
||||
).create({})
|
||||
self.assertEqual(set(wizard.partner_ids.ids), set(partners.ids))
|
||||
|
||||
def test_selected_scope_no_partners_raises(self):
|
||||
wizard = self.env['fusion.batch.followup.wizard'].create({
|
||||
'scope': 'selected', 'partner_ids': [(6, 0, [])],
|
||||
})
|
||||
with self.assertRaises(UserError):
|
||||
wizard.action_run()
|
||||
|
||||
def test_run_completes_with_no_overdue_partners(self):
|
||||
partners = self.env['res.partner'].create([
|
||||
{'name': 'NoOverdue1'}, {'name': 'NoOverdue2'},
|
||||
])
|
||||
wizard = self.env['fusion.batch.followup.wizard'].create({
|
||||
'scope': 'selected',
|
||||
'partner_ids': [(6, 0, partners.ids)],
|
||||
'force': True,
|
||||
})
|
||||
wizard.action_run()
|
||||
self.assertEqual(wizard.state, 'done')
|
||||
# 2 partners with no overdue → both skipped
|
||||
self.assertEqual(wizard.skipped_count, 2)
|
||||
37
fusion_accounting_followup/tests/test_coexistence.py
Normal file
37
fusion_accounting_followup/tests/test_coexistence.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Coexistence tests: fusion_accounting_followup menu only visible when
|
||||
Enterprise account_followup is NOT installed."""
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestFollowupCoexistence(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.coex_group = self.env.ref(
|
||||
'fusion_accounting_core.group_fusion_show_when_enterprise_absent',
|
||||
raise_if_not_found=False,
|
||||
)
|
||||
self.assertIsNotNone(self.coex_group, "Coexistence group must exist")
|
||||
|
||||
def test_engine_always_available(self):
|
||||
self.assertIn('fusion.followup.engine', self.env.registry)
|
||||
|
||||
def test_menu_gated_by_coexistence_group(self):
|
||||
menu = self.env.ref('fusion_accounting_followup.menu_fusion_followup_root',
|
||||
raise_if_not_found=False)
|
||||
if not menu:
|
||||
self.skipTest("Menu not loaded")
|
||||
menu_groups = getattr(menu, 'group_ids', None) or menu.groups_id
|
||||
self.assertIn(self.coex_group, menu_groups,
|
||||
"Followup root menu must require the coexistence group")
|
||||
|
||||
def test_levels_menu_gated(self):
|
||||
menu = self.env.ref('fusion_accounting_followup.menu_fusion_followup_levels',
|
||||
raise_if_not_found=False)
|
||||
if not menu:
|
||||
self.skipTest("Menu not loaded")
|
||||
menu_groups = getattr(menu, 'group_ids', None) or menu.groups_id
|
||||
self.assertIn(self.coex_group, menu_groups)
|
||||
@@ -6,8 +6,9 @@ from odoo.tests import tagged
|
||||
class TestFusionFollowupLevel(TransactionCase):
|
||||
|
||||
def test_create_minimal(self):
|
||||
# Note: sequences 1-3 are reserved for seeded default levels.
|
||||
level = self.env['fusion.followup.level'].create({
|
||||
'name': 'Reminder', 'sequence': 1, 'delay_days': 7, 'tone': 'gentle',
|
||||
'name': 'Reminder', 'sequence': 901, 'delay_days': 7, 'tone': 'gentle',
|
||||
})
|
||||
self.assertEqual(level.name, 'Reminder')
|
||||
self.assertTrue(level.active)
|
||||
@@ -15,7 +16,7 @@ class TestFusionFollowupLevel(TransactionCase):
|
||||
def test_negative_delay_rejected(self):
|
||||
with self.assertRaises(Exception):
|
||||
self.env['fusion.followup.level'].create({
|
||||
'name': 'Bad', 'sequence': 1, 'delay_days': -5, 'tone': 'gentle',
|
||||
'name': 'Bad', 'sequence': 902, 'delay_days': -5, 'tone': 'gentle',
|
||||
})
|
||||
|
||||
def test_duplicate_sequence_rejected(self):
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestFollowupMigrationRoundTrip(TransactionCase):
|
||||
|
||||
def test_bootstrap_step_runs(self):
|
||||
wizard = self.env['fusion.migration.wizard'].create({})
|
||||
result = wizard._followup_bootstrap_step()
|
||||
self.assertEqual(result['step'], 'followup_bootstrap')
|
||||
# Either Enterprise present or not — both OK
|
||||
self.assertIn(result['enterprise_module_present'], [True, False])
|
||||
|
||||
def test_bootstrap_idempotent(self):
|
||||
wizard = self.env['fusion.migration.wizard'].create({})
|
||||
first = wizard._followup_bootstrap_step()
|
||||
second = wizard._followup_bootstrap_step()
|
||||
# Second run skips what first created (or both no-op)
|
||||
if first['enterprise_module_present']:
|
||||
self.assertGreaterEqual(second['skipped'], first['created'])
|
||||
69
fusion_accounting_followup/views/menu_views.xml
Normal file
69
fusion_accounting_followup/views/menu_views.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- Top-level menu (visible only when account_followup Enterprise NOT installed) -->
|
||||
<menuitem id="menu_fusion_followup_root"
|
||||
name="Customer Follow-ups"
|
||||
sequence="70"
|
||||
web_icon="fusion_accounting_followup,static/description/icon.png"
|
||||
groups="fusion_accounting_core.group_fusion_show_when_enterprise_absent"/>
|
||||
|
||||
<!-- Partners list (gated to overdue) -->
|
||||
<record id="action_fusion_followup_partners" model="ir.actions.act_window">
|
||||
<field name="name">Overdue Customers</field>
|
||||
<field name="res_model">res.partner</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
<field name="domain">[('fusion_followup_status', 'in', ('action_due', 'paused', 'blocked', 'with_credit_team'))]</field>
|
||||
<field name="context">{}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
Customer follow-ups
|
||||
</p>
|
||||
<p>
|
||||
AI-augmented dunning sequences for unpaid invoices.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_fusion_followup_partners"
|
||||
name="Overdue Customers"
|
||||
parent="menu_fusion_followup_root"
|
||||
action="action_fusion_followup_partners"
|
||||
sequence="10"
|
||||
groups="fusion_accounting_core.group_fusion_show_when_enterprise_absent"/>
|
||||
|
||||
<!-- Levels config -->
|
||||
<record id="action_fusion_followup_levels" model="ir.actions.act_window">
|
||||
<field name="name">Follow-up Levels</field>
|
||||
<field name="res_model">fusion.followup.level</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_fusion_followup_levels"
|
||||
name="Levels"
|
||||
parent="menu_fusion_followup_root"
|
||||
action="action_fusion_followup_levels"
|
||||
sequence="20"
|
||||
groups="fusion_accounting_core.group_fusion_show_when_enterprise_absent"/>
|
||||
|
||||
<!-- Run history -->
|
||||
<record id="action_fusion_followup_runs" model="ir.actions.act_window">
|
||||
<field name="name">Follow-up History</field>
|
||||
<field name="res_model">fusion.followup.run</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_fusion_followup_runs"
|
||||
name="History"
|
||||
parent="menu_fusion_followup_root"
|
||||
action="action_fusion_followup_runs"
|
||||
sequence="30"
|
||||
groups="fusion_accounting_core.group_fusion_show_when_enterprise_absent"/>
|
||||
|
||||
<!-- Batch wizard -->
|
||||
<menuitem id="menu_fusion_followup_batch"
|
||||
name="Batch Send..."
|
||||
parent="menu_fusion_followup_root"
|
||||
action="action_fusion_batch_followup_wizard"
|
||||
sequence="40"
|
||||
groups="fusion_accounting_core.group_fusion_show_when_enterprise_absent"/>
|
||||
</odoo>
|
||||
@@ -0,0 +1 @@
|
||||
from . import batch_followup_wizard
|
||||
|
||||
91
fusion_accounting_followup/wizards/batch_followup_wizard.py
Normal file
91
fusion_accounting_followup/wizards/batch_followup_wizard.py
Normal file
@@ -0,0 +1,91 @@
|
||||
"""Batch send follow-ups to selected partners (or all overdue)."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class FusionBatchFollowupWizard(models.TransientModel):
|
||||
_name = "fusion.batch.followup.wizard"
|
||||
_description = "Batch Send Follow-ups Wizard"
|
||||
|
||||
scope = fields.Selection([
|
||||
('selected', 'Selected partners only'),
|
||||
('all_overdue', 'All overdue partners'),
|
||||
], required=True, default='selected')
|
||||
partner_ids = fields.Many2many('res.partner',
|
||||
default=lambda self: self._default_partner_ids())
|
||||
force = fields.Boolean(string='Force (override pause + manual review)',
|
||||
default=False)
|
||||
auto_resolve_level = fields.Boolean(
|
||||
string='Auto-resolve level',
|
||||
default=True,
|
||||
help="If True, engine picks the appropriate level per partner. "
|
||||
"If False, use the chosen override level for all.")
|
||||
override_level_id = fields.Many2one('fusion.followup.level')
|
||||
|
||||
# Results
|
||||
state = fields.Selection([('draft', 'Draft'), ('done', 'Done')], default='draft')
|
||||
sent_count = fields.Integer(readonly=True)
|
||||
skipped_count = fields.Integer(readonly=True)
|
||||
error_count = fields.Integer(readonly=True)
|
||||
summary = fields.Text(readonly=True)
|
||||
|
||||
@api.model
|
||||
def _default_partner_ids(self):
|
||||
ctx = self.env.context
|
||||
if ctx.get('active_model') == 'res.partner':
|
||||
return ctx.get('active_ids', [])
|
||||
return []
|
||||
|
||||
def action_run(self):
|
||||
self.ensure_one()
|
||||
if self.scope == 'selected' and not self.partner_ids:
|
||||
raise UserError(_("No partners selected."))
|
||||
|
||||
partners = self.partner_ids
|
||||
if self.scope == 'all_overdue':
|
||||
Line = self.env['account.move.line'].sudo()
|
||||
overdue_partner_ids = Line.search([
|
||||
('parent_state', '=', 'posted'),
|
||||
('account_id.account_type', '=', 'asset_receivable'),
|
||||
('reconciled', '=', False),
|
||||
('amount_residual', '>', 0),
|
||||
('date_maturity', '<', date.today()),
|
||||
('company_id', '=', self.env.company.id),
|
||||
]).mapped('partner_id').ids
|
||||
partners = self.env['res.partner'].sudo().browse(overdue_partner_ids)
|
||||
|
||||
engine = self.env['fusion.followup.engine']
|
||||
sent = 0
|
||||
skipped = 0
|
||||
errors = []
|
||||
for partner in partners:
|
||||
try:
|
||||
with self.env.cr.savepoint():
|
||||
level = self.override_level_id if not self.auto_resolve_level else None
|
||||
result = engine.send_followup_email(
|
||||
partner, level=level, force=self.force)
|
||||
status = result.get('status', '')
|
||||
if status == 'sent':
|
||||
sent += 1
|
||||
else:
|
||||
skipped += 1
|
||||
except Exception as e:
|
||||
errors.append(f"{partner.name}: {e}")
|
||||
|
||||
self.write({
|
||||
'state': 'done',
|
||||
'sent_count': sent,
|
||||
'skipped_count': skipped,
|
||||
'error_count': len(errors),
|
||||
'summary': '\n'.join(errors[:20]) if errors else False,
|
||||
})
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': self._name,
|
||||
'res_id': self.id,
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_fusion_batch_followup_wizard_form" model="ir.ui.view">
|
||||
<field name="name">fusion.batch.followup.wizard.form</field>
|
||||
<field name="model">fusion.batch.followup.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Batch Follow-ups">
|
||||
<group invisible="state == 'done'">
|
||||
<field name="scope" widget="radio"/>
|
||||
<field name="partner_ids" widget="many2many_tags"
|
||||
invisible="scope != 'selected'"
|
||||
required="scope == 'selected'"/>
|
||||
<field name="auto_resolve_level"/>
|
||||
<field name="override_level_id"
|
||||
options="{'no_create': True}"
|
||||
invisible="auto_resolve_level"
|
||||
required="not auto_resolve_level"/>
|
||||
<field name="force"/>
|
||||
</group>
|
||||
<group invisible="state != 'done'" string="Results">
|
||||
<field name="sent_count"/>
|
||||
<field name="skipped_count"/>
|
||||
<field name="error_count"/>
|
||||
<field name="summary"/>
|
||||
</group>
|
||||
<field name="state" invisible="1"/>
|
||||
<footer>
|
||||
<button name="action_run" type="object" string="Run"
|
||||
class="btn-primary" invisible="state == 'done'"/>
|
||||
<button special="cancel" string="Close"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_fusion_batch_followup_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Batch Send Follow-ups</field>
|
||||
<field name="res_model">fusion.batch.followup.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="binding_model_id" ref="base.model_res_partner"/>
|
||||
<field name="binding_view_types">list</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user