From 780f1a71a5fe3d053b0163f7be495497c84349d7 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 18 Jan 2023 14:34:26 +0700 Subject: add salesname, and achievement in sales target --- indoteknik_custom/models/sales_target.py | 18 ++++++++++++++++++ indoteknik_custom/views/sales_target.xml | 21 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sales_target.py b/indoteknik_custom/models/sales_target.py index ac6405e5..9069fa6a 100644 --- a/indoteknik_custom/models/sales_target.py +++ b/indoteknik_custom/models/sales_target.py @@ -16,6 +16,24 @@ class SalesTarget(models.Model): ongoing_omset_adempiere = fields.Float(string='Omset Berjalan ADempiere') ongoing_omset_total = fields.Float(string='Total Omset', compute='_compute_total_omset') target = fields.Float(string='Target') + ach_per_year = fields.Float(string='Ach/Year%', compute='_compute_achievement') + ach_per_month = fields.Float(string='Ach/Month%', compute='_compute_achievement') + sales_id = fields.Many2one('res.users', string='Salesperson', compute='_compute_salesperson') + + def _compute_salesperson(self): + for sales_target in self: + sales_target.sales_id = sales_target.partner_id.user_id + + def _compute_achievement(self): + for sales_target in self: + if not sales_target.target or sales_target.target <= 0: + sales_target.ach_per_year = 0 + sales_target.ach_per_month = 0 + return + current_time = datetime.now() + current_month = current_time.month + sales_target.ach_per_year = sales_target.ongoing_omset_total/sales_target.target*100 + sales_target.ach_per_month = sales_target.ongoing_omset_total/((sales_target.target/12)*current_month) def _compute_total_omset(self): for target in self: diff --git a/indoteknik_custom/views/sales_target.xml b/indoteknik_custom/views/sales_target.xml index 6ccea260..b77ea5d4 100644 --- a/indoteknik_custom/views/sales_target.xml +++ b/indoteknik_custom/views/sales_target.xml @@ -1,26 +1,39 @@ + + sales.target.list.select + sales.target + + + + + + + + Sales Target sales.target + tree,form - Sales Target sales.target + + + - Sales Target sales.target @@ -30,12 +43,16 @@ + + + + -- cgit v1.2.3