Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] crm_last_dates: Improve child_ids #169

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading