summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
-rwxr-xr-xindoteknik_custom/models/product_template.py130
1 files changed, 107 insertions, 23 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 25473ab8..5bedae13 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -1,11 +1,13 @@
-from odoo import fields, models, api
+from odoo import fields, models, api, tools, _
from datetime import datetime, timedelta, date
from odoo.exceptions import UserError
import logging
import requests
import json
import re
+import qrcode, base64
from bs4 import BeautifulSoup
+from io import BytesIO
_logger = logging.getLogger(__name__)
@@ -58,14 +60,35 @@ class ProductTemplate(models.Model):
('sp', 'Spare Part'),
('acc', 'Accessories')
], string='Kind of', copy=False)
- sni = fields.Boolean(string='SNI')
+ sni = fields.Boolean(string='SNI')
tkdn = fields.Boolean(string='TKDN')
short_spesification = fields.Char(string='Short Spesification')
+ merchandise_ok = fields.Boolean(string='Product Promotion')
+ print_barcode = fields.Boolean(string='Print Barcode', default=True)
+ # qr_code = fields.Binary("QR Code", compute='_compute_qr_code')
+
+ # def _compute_qr_code(self):
+ # for rec in self.product_variant_ids:
+ # qr = qrcode.QRCode(
+ # version=1,
+ # error_correction=qrcode.constants.ERROR_CORRECT_L,
+ # box_size=5,
+ # border=4,
+ # )
+ # qr.add_data(rec.display_name)
+ # qr.make(fit=True)
+ # img = qr.make_image(fill_color="black", back_color="white")
+
+ # buffer = BytesIO()
+ # img.save(buffer, format="PNG")
+ # qr_code_img = base64.b64encode(buffer.getvalue()).decode()
+
+ # rec.qr_code = qr_code_img
@api.constrains('name', 'internal_reference', 'x_manufacture')
def required_public_categ_ids(self):
for rec in self:
- if not rec.public_categ_ids:
+ if not rec.public_categ_ids and rec.type == 'product':
raise UserError('Field Categories harus diisi')
def _get_qty_sold(self):
@@ -377,6 +400,31 @@ class ProductProduct(models.Model):
max_qty_reorder = fields.Float(string='Max Qty Reorder', compute='_get_max_qty_reordering_rule')
qty_rpo = fields.Float(string='Qty RPO', compute='_get_qty_rpo')
plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product')
+ merchandise_ok = fields.Boolean(string='Product Promotion')
+ qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant')
+
+ def _compute_qr_code_variant(self):
+ for rec in self:
+ # Skip inactive variants
+ if not rec.active:
+ rec.qr_code_variant = False # Clear the QR Code for archived variants
+ continue
+
+ qr = qrcode.QRCode(
+ version=1,
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
+ box_size=5,
+ border=4,
+ )
+ qr.add_data(rec.default_code)
+ qr.make(fit=True)
+ img = qr.make_image(fill_color="black", back_color="white")
+
+ buffer = BytesIO()
+ img.save(buffer, format="PNG")
+ qr_code_img = base64.b64encode(buffer.getvalue()).decode()
+
+ rec.qr_code_variant = qr_code_img
def _get_clean_website_description(self):
for rec in self:
@@ -386,7 +434,7 @@ class ProductProduct(models.Model):
@api.constrains('name', 'internal_reference', 'x_manufacture')
def required_public_categ_ids(self):
for rec in self:
- if not rec.public_categ_ids:
+ if not rec.public_categ_ids and rec.type == 'product':
raise UserError('Field Categories harus diisi')
@api.constrains('active')
@@ -482,33 +530,38 @@ class ProductProduct(models.Model):
def _get_qty_incoming_bandengan(self):
for product in self:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', product.id),
- ('location_dest_id', 'in', [57, 83]),
- ('state', 'not in', ['done', 'cancel'])
- ])
- qty = sum(qty_incoming.mapped('product_uom_qty'))
+ qty = self.env['v.move.outstanding'].read_group(
+ domain=[
+ ('product_id', '=', product.id),
+ ('location_dest_id', 'in', [57, 83]),
+ ],
+ fields=['qty_need'],
+ groupby=[]
+ )[0].get('qty_need', 0.0)
product.qty_incoming_bandengan = qty
def _get_qty_incoming_bandengan_with_exclude(self):
for product in self:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', product.id),
- ('location_dest_id', 'in', [57, 83]),
- ('state', 'not in', ['done', 'cancel'])
- ])
- qty = sum(qty_incoming.mapped('product_uom_qty'))
+ qty = self.env['v.move.outstanding'].read_group(
+ domain=[
+ ('product_id', '=', product.id),
+ ('location_dest_id', 'in', [57, 83]),
+ ],
+ fields=['qty_need'],
+ groupby=[]
+ )[0].get('qty_need', 0.0)
product.qty_incoming_bandengan = qty
def _get_qty_outgoing_bandengan(self):
for product in self:
- qty_incoming = self.env['stock.move'].search([
- ('product_id', '=', product.id),
- ('location_dest_id', '=', 5),
- ('location_id', 'in', [57, 83]),
- ('state', 'not in', ['done', 'cancel'])
- ])
- qty = sum(qty_incoming.mapped('product_uom_qty'))
+ qty = self.env['v.move.outstanding'].read_group(
+ domain=[
+ ('product_id', '=', product.id),
+ ('location_id', 'in', [57, 83]),
+ ],
+ fields=['qty_need'],
+ groupby=[]
+ )[0].get('qty_need', 0.0)
product.qty_outgoing_bandengan = qty
def _get_qty_onhand_bandengan(self):
@@ -598,3 +651,34 @@ class ProductProduct(models.Model):
('end_date', '>=', current_time)
], limit=1)
return pricelist
+
+
+class OutstandingMove(models.Model):
+ _name = 'v.move.outstanding'
+ _auto = False
+ _rec_name = 'id'
+
+ id = fields.Integer(string='ID')
+ product_id = fields.Many2one('product.product', string='Product')
+ reference = fields.Char(string='Reference', help='Nomor Dokumen terkait')
+ qty_need = fields.Float(string='Qty Need', help='Qty yang akan outgoing / incoming')
+ location_id = fields.Many2one('stock.location', string='Location', help='Lokasi asal')
+ location_dest_id = fields.Many2one('stock.location', string='Location To', help='Lokasi tujuan')
+
+ def init(self):
+ # where clause 'state in' follow the origin of outgoing and incoming odoo
+ tools.drop_view_if_exists(self.env.cr, self._table)
+ self.env.cr.execute("""
+ CREATE OR REPLACE VIEW %s AS
+ select sm.id, sm.reference, sm.product_id,
+ sm.product_uom_qty as qty_need,
+ sm.location_id, sm.location_dest_id
+ from stock_move sm
+ where 1=1
+ and sm.state in(
+ 'waiting',
+ 'confirmed',
+ 'assigned',
+ 'partially_available'
+ )
+ """ % self._table)