Skip to content

Commit

Permalink
Change leads stage when invoice paid
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierteres committed Nov 11, 2022
1 parent dd2b3f5 commit d7bd628
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions som_generationkwh/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def pay_and_reconcile(self, cursor, uid, ids, pay_amount,
pay_journal_id, writeoff_acc_id, writeoff_period_id,
writeoff_journal_id, context, name
)

#TODO: Untested
today = str(date.today()) #TODO date more real?
Investment = self.pool.get('generationkwh.investment')
Expand All @@ -45,8 +46,25 @@ def pay_and_reconcile(self, cursor, uid, ids, pay_amount,
Investment.mark_as_interested(cursor, uid, invoice_id)
if self.is_investment_payment(cursor,uid,invoice_id):
Investment.mark_as_paid(cursor,uid,[investment_id],today,moveline_id)
self.change_leads_stage(cursor, uid, ids)

return res

def change_leads_stage(self, cursor, uid, ids):
lead_o = self.pool.get("som.soci.crm.lead")

leads_to_change = []
for id in ids:
lead_id = lead_o.search(cursor, uid, [('invoice_id', '=', id)])
if len(lead_id) <= 0:
continue
lead = lead_o.browse(cursor, uid, lead_id[0])
invoice = self.browse(cursor, uid, id)
if invoice.state == 'paid' and lead.stage_id.name == 'Remesat':
leads_to_change.append(lead_id[0])

lead_o.stage_next(cursor, uid, leads_to_change)

def is_interest_payment(self, cursor, uid, invoice_id):
ir_md_obj = self.pool.get('ir.model.data')
apo_journal = ir_md_obj.get_object_reference(
Expand Down

0 comments on commit d7bd628

Please sign in to comment.