feat(fusion_accounting_ai): add Followup and Assets data adapters
Made-with: Cursor
This commit is contained in:
47
fusion_accounting_ai/services/data_adapters/followup.py
Normal file
47
fusion_accounting_ai/services/data_adapters/followup.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Follow-up data adapter."""
|
||||
|
||||
from datetime import date, timedelta
|
||||
from .base import DataAdapter
|
||||
from ._registry import register_adapter
|
||||
|
||||
|
||||
class FollowupAdapter(DataAdapter):
|
||||
FUSION_MODEL = 'fusion.followup.line'
|
||||
ENTERPRISE_MODULE = 'account_followup'
|
||||
|
||||
def overdue_invoices(self, days_overdue=30, partner_id=None):
|
||||
return self._dispatch('overdue_invoices', days_overdue=days_overdue, partner_id=partner_id)
|
||||
|
||||
def overdue_invoices_via_fusion(self, days_overdue=30, partner_id=None):
|
||||
return self.overdue_invoices_via_community(days_overdue=days_overdue, partner_id=partner_id)
|
||||
|
||||
def overdue_invoices_via_enterprise(self, days_overdue=30, partner_id=None):
|
||||
return self.overdue_invoices_via_community(days_overdue=days_overdue, partner_id=partner_id)
|
||||
|
||||
def overdue_invoices_via_community(self, days_overdue=30, partner_id=None):
|
||||
cutoff = date.today() - timedelta(days=days_overdue)
|
||||
domain = [
|
||||
('move_type', 'in', ('out_invoice', 'out_refund')),
|
||||
('state', '=', 'posted'),
|
||||
('payment_state', 'in', ('not_paid', 'partial')),
|
||||
('invoice_date_due', '<=', cutoff),
|
||||
]
|
||||
if partner_id:
|
||||
domain.append(('partner_id', '=', partner_id))
|
||||
moves = self.env['account.move'].sudo().search(domain, limit=200, order='invoice_date_due asc')
|
||||
return [
|
||||
{
|
||||
'id': m.id,
|
||||
'name': m.name,
|
||||
'partner_id': m.partner_id.id,
|
||||
'partner_name': m.partner_id.name,
|
||||
'invoice_date_due': m.invoice_date_due,
|
||||
'amount_residual': m.amount_residual,
|
||||
'currency_id': m.currency_id.id,
|
||||
'days_overdue': (date.today() - m.invoice_date_due).days,
|
||||
}
|
||||
for m in moves
|
||||
]
|
||||
|
||||
|
||||
register_adapter('followup', FollowupAdapter)
|
||||
Reference in New Issue
Block a user