summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-12-26 17:39:05 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-12-26 17:39:05 +0700
commitf9f4b55c57461fa7cb0a4d3fb6fc9e85f53fe9c2 (patch)
tree9945b3df169eeddd790cd0f40df673ece17bf2d1 /indoteknik_custom/models
parentdb2f280683b29ac5d32158f3fab0f3df671935e9 (diff)
window sales target
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rwxr-xr-xindoteknik_custom/models/product_template.py16
-rw-r--r--indoteknik_custom/models/sales_target.py54
3 files changed, 71 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index dc85ce96..c8cd85b5 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -35,3 +35,4 @@ from . import website_user_wishlist
from . import website_brand_homepage
from . import mail_mail
from . import website_categories_homepage
+from . import sales_target
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 9ddaf91c..dbbd4ad4 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -36,6 +36,14 @@ class ProductTemplate(models.Model):
search_rank = fields.Integer(string='Search Rank', default=0)
search_rank_weekly = fields.Integer(string='Search Rank Weekly', default=0)
supplier_url = fields.Char(string='Vendor URL')
+ # custom field for support Trusco products
+ maker_code = fields.Char(string='Maker Code')
+ maker_name = fields.Char(string='Maker Name')
+ origin = fields.Char(string='Origin')
+ features = fields.Char(string='Features')
+ usage = fields.Char(string='Usage')
+ specification = fields.Char(string='Specification')
+ material = fields.Char(string='Material')
# def write(self, vals):
# if 'solr_flag' not in vals and self.solr_flag == 1:
@@ -182,6 +190,14 @@ class ProductProduct(models.Model):
'Qty Stock Vendor', compute='_compute_stock_vendor',
help="Stock Vendor")
solr_flag = fields.Integer(string='Solr Flag', default=0)
+ # custom field for support Trusco products
+ maker_code = fields.Char(string='Maker Code')
+ maker_name = fields.Char(string='Maker Name')
+ origin = fields.Char(string='Origin')
+ features = fields.Char(string='Features')
+ usage = fields.Char(string='Usage')
+ specification = fields.Char(string='Specification')
+ material = fields.Char(string='Material')
# def write(self, vals):
# if 'solr_flag' not in vals:
diff --git a/indoteknik_custom/models/sales_target.py b/indoteknik_custom/models/sales_target.py
new file mode 100644
index 00000000..5d2d6310
--- /dev/null
+++ b/indoteknik_custom/models/sales_target.py
@@ -0,0 +1,54 @@
+from odoo import fields, models, api
+from datetime import datetime, timedelta
+import logging
+
+_logger = logging.getLogger(__name__)
+
+
+class SalesTarget(models.Model):
+ _name = 'sales.target'
+
+ partner_id = fields.Many2one('res.partner', string='Customer')
+ period = fields.Integer(string='Periode')
+ omset_last_year = fields.Float(string='Omset Tahun Lalu')
+ ongoing_omset_odoo = fields.Float(string='Omset Berjalan Odoo', compute='_compute_ongoing_omset')
+ ongoing_omset_accurate = fields.Float(string='Omset Berjalan Accurate')
+ ongoing_omset_adempiere = fields.Float(string='Omset Berjalan ADempiere')
+ ongoing_omset_total = fields.Float(string='Total Omset', compute='_compute_total_omset')
+
+ def _compute_total_omset(self):
+ for target in self:
+ target.ongoing_omset_total = target.ongoing_omset_odoo + target.ongoing_omset_accurate + target.ongoing_omset_adempiere
+
+ def _compute_ongoing_omset(self):
+ for target in self:
+ target.ongoing_omset_odoo = 0
+ if not target.ids:
+ return True
+
+ partners = []
+ if target.partner_id.parent_id:
+ parent_id = target.partner_id.parent_id
+ else:
+ parent_id = target.partner_id
+ partners += parent_id.child_ids
+ partners.append(parent_id)
+
+ datefrom = datetime(target.period, 1, 1, 00, 00)
+ # datefrom = datefrom.strftime('%Y-%m-%d %H:%M:%S')
+ dateto = datetime(target.period, 12, 31, 23, 59)
+ # dateto = dateto.strftime('%Y-%m-%d %H:%M:%S')
+
+ total_omset = 0
+ for partner in partners:
+ domain = [
+ ('partner_id', '=', partner.id),
+ ('state', 'not in', ['draft', 'cancel']),
+ ('move_type', 'in', ('out_invoice', 'out_refund')),
+ ('invoice_date', '>=', datefrom),
+ ('invoice_date', '<=', dateto)
+ ]
+ invoices = target.env['account.move'].search(domain)
+ for invoice in invoices:
+ total_omset += invoice.amount_untaxed
+ target.ongoing_omset_odoo = total_omset