diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-01-04 14:52:28 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-01-04 14:52:28 +0700 |
| commit | 7cc4bec031757d23c7f7f9e754fc2997d2dfd921 (patch) | |
| tree | 2ace5dc432e04a4d8f91be276b3c8b83adda3935 /indoteknik_custom/models | |
| parent | 3a5407d507ff985e10b4675727643bf5af107d11 (diff) | |
| parent | b0f4f1875216bbb0347c082f38b91b59e5bbf50c (diff) | |
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 6 | ||||
| -rw-r--r-- | indoteknik_custom/models/customer_review.py | 16 | ||||
| -rw-r--r-- | indoteknik_custom/models/product_spec.py | 19 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 16 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 20 | ||||
| -rw-r--r-- | indoteknik_custom/models/purchase_outstanding.py | 33 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 66 | ||||
| -rw-r--r-- | indoteknik_custom/models/sales_outstanding.py | 33 | ||||
| -rw-r--r-- | indoteknik_custom/models/sales_target.py | 55 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_content.py | 34 | ||||
| -rwxr-xr-x | indoteknik_custom/models/x_manufactures.py | 20 |
11 files changed, 312 insertions, 6 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index dc85ce96..d7d3e03c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -35,3 +35,9 @@ from . import website_user_wishlist from . import website_brand_homepage from . import mail_mail from . import website_categories_homepage +from . import sales_target +from . import product_spec +from . import purchase_outstanding +from . import sales_outstanding +from . import customer_review +from . import website_content diff --git a/indoteknik_custom/models/customer_review.py b/indoteknik_custom/models/customer_review.py new file mode 100644 index 00000000..5fb93b2e --- /dev/null +++ b/indoteknik_custom/models/customer_review.py @@ -0,0 +1,16 @@ +from odoo import fields, models, api + + +class CustomerReview(models.Model): + _name = 'customer.review' + + sequence = fields.Integer(string='Sequence') + customer_name = fields.Char(string='Customer') + image = fields.Binary(string='Image') + ulasan = fields.Char(string='Ulasan') + name = fields.Char(string='Name') + jabatan = fields.Char(string='Jabatan') + status = fields.Selection([ + ('tayang', 'Tayang'), + ('tidak_tayang', 'Tidak Tayang') + ], string='Status') diff --git a/indoteknik_custom/models/product_spec.py b/indoteknik_custom/models/product_spec.py new file mode 100644 index 00000000..161438b6 --- /dev/null +++ b/indoteknik_custom/models/product_spec.py @@ -0,0 +1,19 @@ +from odoo import fields, models, api +from datetime import datetime, timedelta +import logging + +_logger = logging.getLogger(__name__) + + +class ProductTemplateSpec(models.Model): + _name = 'product.template.spec' + product_tmpl_id = fields.Many2one('product.template', string='Product Template') + attribute = fields.Char(string='Attribute', help='Attribute of Product') + value = fields.Char(string='Values', help='Value of Attribute') + + +class ProductVariantSpec(models.Model): + _name = 'product.variant.spec' + product_variant_id = fields.Many2one('product.product', string='Product Variant') + attribute = fields.Char(string='Attribute', help='Attribute of Product') + value = fields.Char(string='Values', help='Value of Attribute') 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/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a816038e..b4d671b6 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -70,19 +70,29 @@ class PurchaseOrder(models.Model): def calculate_po_status(self): purchases = self.env['purchase.order'].search([ ('po_status', '!=', 'terproses'), + # ('id', '=', 213), ]) for order in purchases: sum_qty_received = sum_qty_po = 0 + + have_outstanding_pick = False + for pick in order.picking_ids: + if pick.state == 'draft' or pick.state == 'assigned' or pick.state == 'confirmed' or pick.state == 'waiting': + have_outstanding_pick = True + for po_line in order.order_line: sum_qty_po += po_line.product_uom_qty sum_qty_received += po_line.qty_received - if order.summary_qty_po == order.summary_qty_receipt: - order.po_status = 'terproses' - elif order.summary_qty_po > order.summary_qty_receipt > 0: - order.po_status = 'sebagian' + if have_outstanding_pick: + # if order.summary_qty_po == order.summary_qty_receipt: + # order.po_status = 'terproses' + if order.summary_qty_po > order.summary_qty_receipt > 0: + order.po_status = 'sebagian' + else: + order.po_status = 'menunggu' else: - order.po_status = 'menunggu' + order.po_status = 'terproses' _logger.info("Calculate PO Status %s" % order.id) def _compute_summary_qty(self): diff --git a/indoteknik_custom/models/purchase_outstanding.py b/indoteknik_custom/models/purchase_outstanding.py new file mode 100644 index 00000000..018ab0ec --- /dev/null +++ b/indoteknik_custom/models/purchase_outstanding.py @@ -0,0 +1,33 @@ +from odoo import fields, models, api, tools + + +class PurchaseOutstanding(models.Model): + _name = 'purchase.outstanding' + _auto = False + _rec_name = 'product_id' + + id = fields.Integer() + order_id = fields.Many2one('purchase.order', string='Nomor PO') + partner_id = fields.Many2one('res.partner', String='Vendor') + user_id = fields.Many2one('res.users', string='Purchaser') + date_order = fields.Datetime(string="Date Order") + po_state = fields.Char(string='State') + po_status = fields.Char(string='PO Status') + product_id = fields.Many2one('product.product', string='Product') + product_uom_qty = fields.Integer(string='Qty PO') + qty_received = fields.Integer(string='Qty Received') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS( + select pol.id as id, po.id as order_id, po.partner_id, po.user_id, + po.date_order, po.state as po_state, po.po_status, + pol.product_id, pol.product_uom_qty, pol.qty_received + from purchase_order_line pol + join purchase_order po on po.id = pol.order_id + where 1=1 + and pol.product_uom_qty <> pol.qty_received + and po_status in ('sebagian','menunggu') + ) + """ % self._table) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index f21a80fe..3f6f5032 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1,9 +1,11 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools.misc import formatLang, get_lang - +import logging import warnings +_logger = logging.getLogger(__name__) + class SaleOrder(models.Model): _inherit = "sale.order" @@ -42,6 +44,68 @@ class SaleOrder(models.Model): domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", help="Dipakai untuk alamat tempel") fee_third_party = fields.Float('Fee Pihak Ketiga') + so_status = fields.Selection([ + ('terproses', 'Terproses'), + ('sebagian', 'Sebagian Diproses'), + ('menunggu', 'Menunggu Diproses'), + ]) + partner_purchase_order_name = fields.Char(string='Nama PO Customer', copy=False, help="Nama purchase order customer, diisi oleh customer melalui website.", tracking=3) + partner_purchase_order_description = fields.Text(string='Keterangan PO Customer', copy=False, help="Keterangan purchase order customer, diisi oleh customer melalui website.", tracking=3) + partner_purchase_order_file = fields.Binary(string='File PO Customer', copy=False, help="File purchase order customer, diisi oleh customer melalui website.") + + def calculate_so_status_beginning(self): + so_state = ['sale'] + sales = self.env['sale.order'].search([ + ('state', 'in', so_state),# must add validation so_status + ]) + for sale in sales: + sum_qty_ship = sum_qty_so = 0 + have_outstanding_pick = False + + for pick in sale.picking_ids: + if pick.state == 'draft' or pick.state == 'assigned' or pick.state == 'confirmed' or pick.state == 'waiting': + have_outstanding_pick = True + + for so_line in sale.order_line: + sum_qty_so += so_line.product_uom_qty + sum_qty_ship += so_line.qty_delivered + + if have_outstanding_pick: + if sum_qty_so > sum_qty_ship > 0: + sale.so_status = 'sebagian' + else: + sale.so_status = 'menunggu' + else: + sale.so_status = 'terproses' + _logger.info('Calculate SO Status %s' % sale.id) + + def calculate_so_status(self): + so_state = ['sale'] + so_status = ['sebagian', 'menunggu'] + sales = self.env['sale.order'].search([ + ('state', 'in', so_state), + ('so_status', 'in', so_status), + ]) + for sale in sales: + sum_qty_ship = sum_qty_so = 0 + have_outstanding_pick = False + + for pick in sale.picking_ids: + if pick.state == 'draft' or pick.state == 'assigned' or pick.state == 'confirmed' or pick.state == 'waiting': + have_outstanding_pick = True + + for so_line in sale.order_line: + sum_qty_so += so_line.product_uom_qty + sum_qty_ship += so_line.qty_delivered + + if have_outstanding_pick: + if sum_qty_so > sum_qty_ship > 0: + sale.so_status = 'sebagian' + else: + sale.so_status = 'menunggu' + else: + sale.so_status = 'terproses' + _logger.info('Calculate SO Status %s' % sale.id) @api.onchange('partner_shipping_id') def onchange_partner_shipping(self): diff --git a/indoteknik_custom/models/sales_outstanding.py b/indoteknik_custom/models/sales_outstanding.py new file mode 100644 index 00000000..645482ff --- /dev/null +++ b/indoteknik_custom/models/sales_outstanding.py @@ -0,0 +1,33 @@ +from odoo import fields, models, api, tools + + +class SalesOutstanding(models.Model): + _name = 'sales.outstanding' + _auto = False + _rec_name = 'product_id' + + id = fields.Integer() + order_id = fields.Many2one('sale.order', string='Nomor SO') + partner_id = fields.Many2one('res.partner', String='Customer') + user_id = fields.Many2one('res.users', string='Salesperson') + date_order = fields.Datetime(string="Date Order") + so_state = fields.Char(string='State') + so_status = fields.Char(string='SO Status') + product_id = fields.Many2one('product.product', string='Product') + product_uom_qty = fields.Integer(string='Qty SO') + qty_delivered = fields.Integer(string='Qty Delivered') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS( + select sol.id as id, so.id as order_id, so.partner_id, so.user_id, + so.date_order, so.state as so_state, so.so_status, + sol.product_id, sol.product_uom_qty, sol.qty_delivered + from sale_order so + join sale_order_line sol on sol.order_id = so.id + where 1=1 + and sol.product_uom_qty <> sol.qty_delivered + and so_status in ('sebagian','menunggu') + ) + """ % self._table) diff --git a/indoteknik_custom/models/sales_target.py b/indoteknik_custom/models/sales_target.py new file mode 100644 index 00000000..ac6405e5 --- /dev/null +++ b/indoteknik_custom/models/sales_target.py @@ -0,0 +1,55 @@ +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') + target = fields.Float(string='Target') + + 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 diff --git a/indoteknik_custom/models/website_content.py b/indoteknik_custom/models/website_content.py new file mode 100644 index 00000000..e94076f8 --- /dev/null +++ b/indoteknik_custom/models/website_content.py @@ -0,0 +1,34 @@ +from odoo import fields, models, api +import logging + +_logger = logging.getLogger(__name__) + + +class WebsiteContent(models.Model): + _name = 'website.content' + + sequence = fields.Integer(string='Sequence') + slide_type = fields.Selection([ + ('document', 'Document'), + ('infographic', 'Infographic'), + ('presentation', 'Presentation'), + ('video', 'Video') + ]) + name = fields.Char(string='Name') + url = fields.Char(string='URL') + channel_id = fields.Many2one('website.content.channel', string='Channel') + status = fields.Selection([ + ('tayang', 'Tayang'), + ('tidak_tayang', 'Tidak Tayang') + ], string='Status') + + +class WebsiteContentChannel(models.Model): + _name = 'website.content.channel' + + name = fields.Char(string='Name') + description_html = fields.Html('Description', sanitize_attributes=False, sanitize_form=False) + visibility = fields.Selection([ + ('public', 'Public'), + ('internal', 'Internal') + ]) diff --git a/indoteknik_custom/models/x_manufactures.py b/indoteknik_custom/models/x_manufactures.py index 24b64c14..1d215cf8 100755 --- a/indoteknik_custom/models/x_manufactures.py +++ b/indoteknik_custom/models/x_manufactures.py @@ -1,5 +1,7 @@ from odoo import models, fields, api +import logging +_logger = logging.getLogger(__name__) class XManufactures(models.Model): _name = 'x_manufactures' @@ -36,6 +38,24 @@ class XManufactures(models.Model): ], string="Jenis Produk") x_short_desc = fields.Text(string="Short Description") product_tmpl_ids = fields.One2many('product.template', 'x_manufacture', string='Product Templates') + cache_reset_status = fields.Selection([ + ('reset', 'Reset'), + ('done', 'Done') + ], string="Cache Reset") + + def cache_reset(self): + manufactures = self.env['x_manufactures'].search([ + ('cache_reset_status', '=', 'reset'), + ]) + for manufacture in manufactures: + products = self.env['product.template'].search([ + ('x_manufacture', '=', manufacture.id), + ('solr_flag', '=', 1), + ]) + for product in products: + product.solr_flag = 2 + _logger.info("Reset Solr Flag to 2 %s" % product.id) + manufacture.cache_reset_status = 'done' @api.onchange('x_name','image_promotion_1','image_promotion_2') def update_solr_flag(self): |
