简体   繁体   中英

Odoo version 13: Email digests & KPI's

I am trying to create a new KPI in the Digests model to show the number of new customers created per week. (Unfortunately, this functionality is not well documented). As documented, I have created two fields in the digest model:

x_studio_kpi_new_customers (Boolean) x_studio_kpi_new_customers_value (Integer)

The value is

for record in self: 
    start, end, company = record._get_kpi_compute_parameters()
    record.x_studio_kpi_new_customers_value = sum(self.env['res.partner'].search([
            ('x_studio_when', '>=', start), 
            ('x_studio_when', '<', end)
    ]).mapped('x_studio_counter'))

x_studio_counter is just the value 1 in all records x_studio_when is the record creation date (have also tried with a datetime field)

I have also tried the code below:

for record in self:
    start, end, company = record._get_kpi_compute_parameters()
    new_customers = self.env['res.partner'].search_count([('x_studio_when', '>=', start), ('x_studio_when', '<', end)])
    record['x_studio_kpi_new_customers_value'] = new_customers

I keep getting 0.

Any help will be appreciated.

In order to build your customized digest, follow these steps:

  1. You may want to add new computed fields with Odoo Studio:

    You must create 2 fields on the digest object:

    • first create a boolean field called kpi_myfield and display it in the KPI's tab;

    • then create a computed field called kpi_myfield_value that will compute your customized KPI.

Create below "compute_kpis_actions" method and after that digest mail able to view count.

def compute_kpis_actions(self, company, user):
        res = super(Digest, self).compute_kpis_actions(company, user)
        res['x_studio_kpi_new_customers'] = 'your_module_name.your_action_name&menu_id=%s' % self.env.ref(your_module_name.your_menu_name').id
        return res

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM