Skip to content

Commit

Permalink
[IMP] crm_last_dates: Improve child_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis committed Oct 11, 2024
1 parent 4e819bd commit 55e0d55
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
18 changes: 12 additions & 6 deletions crm_last_dates/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ class ResPartner(models.Model):
store=True,
)

@api.depends("commercial_partner_id", "opportunity_ids")
@api.depends("commercial_partner_id", "opportunity_ids", "child_ids")
def _compute_last_lead_date(self):
for partner in self:
lead_dates = partner.mapped("opportunity_ids.create_date")
lead_dates = partner.mapped("opportunity_ids.create_date") + partner.mapped(
"child_ids.opportunity_ids.create_date"
)
partner.last_lead_date = max(lead_dates) if lead_dates else False

@api.depends("commercial_partner_id", "meeting_ids")
@api.depends("commercial_partner_id", "meeting_ids", "child_ids")
def _compute_last_meeting_date(self):
for partner in self:
meeting_dates = partner.mapped("meeting_ids.create_date")
meeting_dates = partner.mapped("meeting_ids.create_date") + partner.mapped(
"child_ids.meeting_ids.create_date"
)
partner.last_meeting_date = max(meeting_dates) if meeting_dates else False

@api.depends("commercial_partner_id", "invoice_ids")
@api.depends("commercial_partner_id", "invoice_ids", "child_ids")
def _compute_last_invoice_date(self):
for partner in self:
invoice_dates = partner.mapped("invoice_ids.create_date")
invoice_dates = partner.mapped("invoice_ids.create_date") + partner.mapped(
"child_ids.invoice_ids.create_date"
)
partner.last_invoice_date = max(invoice_dates) if invoice_dates else False
33 changes: 33 additions & 0 deletions crm_last_dates/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,37 @@
</xpath>
</field>
</record>

<record id="action_crm_last_dates" model="ir.actions.server">
<field name="name">CRM Last Dates</field>
<field name="model_id" ref="base.model_res_partner" />
<field name="state">code</field>
<field name="code">
partners = env['res.partner'].search([])

for partner in partners:
# Calcular la última fecha de lead
lead_dates = partner.mapped("opportunity_ids.create_date") + \
partner.mapped("child_ids.opportunity_ids.create_date")
last_lead_date = max(lead_dates) if lead_dates else False

# Calcular la última fecha de reunión
meeting_dates = partner.mapped("meeting_ids.create_date") + \
partner.mapped("child_ids.meeting_ids.create_date")
last_meeting_date = max(meeting_dates) if meeting_dates else False

# Calcular la última fecha de factura
invoice_dates = partner.mapped("invoice_ids.create_date") + \
partner.mapped("child_ids.invoice_ids.create_date")
last_invoice_date = max(invoice_dates) if invoice_dates else False

# Usar write para actualizar los campos
partner.write({
'last_lead_date': last_lead_date,
'last_meeting_date': last_meeting_date,
'last_invoice_date': last_invoice_date,
})
</field>
</record>

</odoo>

0 comments on commit 55e0d55

Please sign in to comment.