From 23c04baabdfe5df35d4aea2849004f86b285ce32 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 26 Nov 2024 14:15:31 +0700 Subject: before testing outgoing and incoming v2 --- indoteknik_custom/models/product_template.py | 79 +++++++++++++++++++++------- 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 25473ab8..3642c0d7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,4 +1,4 @@ -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 @@ -482,33 +482,48 @@ 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['stock.move'].read_group( + domain=[ + ('product_id', '=', product.id), + ('location_dest_id', 'in', [57, 83]), + ('state', 'not in', ['done', 'cancel', 'draft']) + ], + fields=['product_uom_qty'], + groupby=[] + )[0].get('product_uom_qty', 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['stock.move'].read_group( + domain=[ + ('product_id', '=', product.id), + ('location_dest_id', 'in', [57, 83]), + ('state', 'not in', ['done', 'cancel', 'draft']) + ], + fields=['product_uom_qty'], + groupby=[] + )[0].get('product_uom_qty', 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_outgoing = self.env['stock.move'].search([ + # ('product_id', '=', product.id), + # # ('location_dest_id', '=', 5), + # ('location_id', 'in', [57, 83]), + # ('state', 'not in', ['done', 'cancel', 'draft']) + # ]) + # qty = sum(qty_outgoing.mapped('product_uom_qty')) + qty = self.env['stock.move'].read_group( + domain=[ + ('product_id', '=', product.id), + ('location_id', 'in', [57, 83]), + ('state', 'not in', ['done', 'cancel', 'draft']) + ], + fields=['product_uom_qty'], + groupby=[] + )[0].get('product_uom_qty', 0.0) product.qty_outgoing_bandengan = qty def _get_qty_onhand_bandengan(self): @@ -598,3 +613,27 @@ class ProductProduct(models.Model): ('end_date', '>=', current_time) ], limit=1) return pricelist + + +class OutstandingMove(models.Model): + _name = 'v.move.oustanding' + _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') + qty_reserved = fields.Float(string='Qty Reserved', help='Qty yang sudah ter-reserved jika outgoing') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS + select sml.id, sm.reference, sm.product_id, + sm.product_uom_qty as qty_need, sml.product_uom_qty as qty_reserved + from stock_move sm + join stock_move_line sml on sml.move_id = sm.id + where 1=1 + and sm.state not in('done', 'cancel', 'draft') + """ % self._table) -- cgit v1.2.3 From 75a1c83707d1c078e3e200e7bc3d3ca39497ad1c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 26 Nov 2024 14:18:22 +0700 Subject: fix typo and add some comment --- indoteknik_custom/models/product_template.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 3642c0d7..df131ff6 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -616,7 +616,7 @@ class ProductProduct(models.Model): class OutstandingMove(models.Model): - _name = 'v.move.oustanding' + _name = 'v.move.outstanding' _auto = False _rec_name = 'id' @@ -627,6 +627,7 @@ class OutstandingMove(models.Model): qty_reserved = fields.Float(string='Qty Reserved', help='Qty yang sudah ter-reserved jika outgoing') 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 @@ -635,5 +636,10 @@ class OutstandingMove(models.Model): from stock_move sm join stock_move_line sml on sml.move_id = sm.id where 1=1 - and sm.state not in('done', 'cancel', 'draft') + and sm.state in( + 'waiting', + 'confirmed', + 'assigned', + 'partially_available' + ) """ % self._table) -- cgit v1.2.3 From 2f5430e4a50d6203f1a0d0b7b70786d766bd235f Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 26 Nov 2024 14:44:36 +0700 Subject: change function of qty before test --- indoteknik_custom/models/product_template.py | 33 +++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index df131ff6..8d044695 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -482,48 +482,38 @@ class ProductProduct(models.Model): def _get_qty_incoming_bandengan(self): for product in self: - qty = self.env['stock.move'].read_group( + qty = self.env['v.move.outstanding'].read_group( domain=[ ('product_id', '=', product.id), ('location_dest_id', 'in', [57, 83]), - ('state', 'not in', ['done', 'cancel', 'draft']) ], - fields=['product_uom_qty'], + fields=['qty_need'], groupby=[] - )[0].get('product_uom_qty', 0.0) + )[0].get('qty_need', 0.0) product.qty_incoming_bandengan = qty def _get_qty_incoming_bandengan_with_exclude(self): for product in self: - qty = self.env['stock.move'].read_group( + qty = self.env['v.move.outstanding'].read_group( domain=[ ('product_id', '=', product.id), ('location_dest_id', 'in', [57, 83]), - ('state', 'not in', ['done', 'cancel', 'draft']) ], - fields=['product_uom_qty'], + fields=['qty_need'], groupby=[] - )[0].get('product_uom_qty', 0.0) + )[0].get('qty_need', 0.0) product.qty_incoming_bandengan = qty def _get_qty_outgoing_bandengan(self): for product in self: - # qty_outgoing = self.env['stock.move'].search([ - # ('product_id', '=', product.id), - # # ('location_dest_id', '=', 5), - # ('location_id', 'in', [57, 83]), - # ('state', 'not in', ['done', 'cancel', 'draft']) - # ]) - # qty = sum(qty_outgoing.mapped('product_uom_qty')) - qty = self.env['stock.move'].read_group( + qty = self.env['v.move.outstanding'].read_group( domain=[ ('product_id', '=', product.id), ('location_id', 'in', [57, 83]), - ('state', 'not in', ['done', 'cancel', 'draft']) ], - fields=['product_uom_qty'], + fields=['qty_reserved'], groupby=[] - )[0].get('product_uom_qty', 0.0) + )[0].get('qty_reserved', 0.0) product.qty_outgoing_bandengan = qty def _get_qty_onhand_bandengan(self): @@ -625,6 +615,8 @@ class OutstandingMove(models.Model): reference = fields.Char(string='Reference', help='Nomor Dokumen terkait') qty_need = fields.Float(string='Qty Need', help='Qty yang akan outgoing / incoming') qty_reserved = fields.Float(string='Qty Reserved', help='Qty yang sudah ter-reserved jika outgoing') + 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 @@ -632,7 +624,8 @@ class OutstandingMove(models.Model): self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS select sml.id, sm.reference, sm.product_id, - sm.product_uom_qty as qty_need, sml.product_uom_qty as qty_reserved + sm.product_uom_qty as qty_need, sml.product_uom_qty as qty_reserved, + sm.location_id, sm.location_dest_id from stock_move sm join stock_move_line sml on sml.move_id = sm.id where 1=1 -- cgit v1.2.3 From 080e5ca9d4f312e2d7938f55e5ce8f7833b18b0d Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 26 Nov 2024 15:18:57 +0700 Subject: fix qty outgoing --- indoteknik_custom/models/product_template.py | 10 ++++------ indoteknik_custom/security/ir.model.access.csv | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 8d044695..fe459ee3 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -511,9 +511,9 @@ class ProductProduct(models.Model): ('product_id', '=', product.id), ('location_id', 'in', [57, 83]), ], - fields=['qty_reserved'], + fields=['qty_need'], groupby=[] - )[0].get('qty_reserved', 0.0) + )[0].get('qty_need', 0.0) product.qty_outgoing_bandengan = qty def _get_qty_onhand_bandengan(self): @@ -614,7 +614,6 @@ class OutstandingMove(models.Model): 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') - qty_reserved = fields.Float(string='Qty Reserved', help='Qty yang sudah ter-reserved jika outgoing') location_id = fields.Many2one('stock.location', string='Location', help='Lokasi asal') location_dest_id = fields.Many2one('stock.location', string='Location To', help='Lokasi tujuan') @@ -623,11 +622,10 @@ class OutstandingMove(models.Model): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS - select sml.id, sm.reference, sm.product_id, - sm.product_uom_qty as qty_need, sml.product_uom_qty as qty_reserved, + 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 - join stock_move_line sml on sml.move_id = sm.id where 1=1 and sm.state in( 'waiting', diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index e817a28d..7b5338d8 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -146,3 +146,4 @@ access_web_find_page,access.web.find.page,model_web_find_page,,1,1,1,1 access_v_requisition_match_po,access.v.requisition.match.po,model_v_requisition_match_po,,1,1,1,1 access_approval_retur_picking,access.approval.retur.picking,model_approval_retur_picking,,1,1,1,1 access_sales_order_fulfillment_v2,access.sales.order.fulfillment.v2,model_sales_order_fulfillment_v2,,1,1,1,1 +access_v_move_outstanding,access.v.move.outstanding,model_v_move_outstanding,,1,1,1,1 -- cgit v1.2.3 From fe3a1e350736fa581b433fcc7241aad44ab994d1 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 29 Nov 2024 13:42:22 +0700 Subject: update code is in bu prodact template --- indoteknik_custom/models/solr/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 87e8370f..e29c6d39 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -77,7 +77,7 @@ class ProductTemplate(models.Model): ('location_id', 'in', target_locations), ]) - is_in_bu = any(quant.available_quantity > 0 for quant in stock_quant) + is_in_bu = True if template.qty_free_bandengan > 0 else False cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text() website_description = template.website_description if cleaned_desc else '' -- cgit v1.2.3 From a17ec171fbc6f21f64df00df9d6781b4d4559790 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 29 Nov 2024 14:03:16 +0700 Subject: back to code is in bu product template --- indoteknik_custom/models/solr/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index e29c6d39..87e8370f 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -77,7 +77,7 @@ class ProductTemplate(models.Model): ('location_id', 'in', target_locations), ]) - is_in_bu = True if template.qty_free_bandengan > 0 else False + is_in_bu = any(quant.available_quantity > 0 for quant in stock_quant) cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text() website_description = template.website_description if cleaned_desc else '' -- cgit v1.2.3 From b98028d3dde66daab9ffbcdefad8e126a231ba3e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Dec 2024 10:41:32 +0700 Subject: take out view fullfilment v1 --- indoteknik_custom/views/sale_order.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index e12130de..703b4d49 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -263,9 +263,9 @@ - + -- cgit v1.2.3 From 87fffacec07389c984f95a86e9e0735dbb6b0665 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Dec 2024 11:35:55 +0700 Subject: Change name column field --- indoteknik_custom/models/sale_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 04fafa69..a31ff569 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -33,7 +33,7 @@ class SaleOrderLine(models.Model): qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved') product_available_quantity = fields.Float(string='Qty pickup by user',) reserved_from = fields.Char(string='Reserved From', copy=False) - item_percent_margin_without_deduction = fields.Float('%Margin', compute='_compute_item_margin_without_deduction') + item_percent_margin_without_deduction = fields.Float('Margin Without Deduction', compute='_compute_item_margin_without_deduction') weight = fields.Float(string='Weight') md_vendor_id = fields.Many2one('res.partner', string='MD Vendor', readonly=True) margin_md = fields.Float(string='Margin MD') -- cgit v1.2.3 From dbe24b9cd600c7b5a9d0587f80a782ed93c9a761 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Dec 2024 13:37:28 +0700 Subject: add name to validation --- indoteknik_custom/models/stock_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 17dd5766..03b10cdb 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -539,7 +539,7 @@ class StockPicking(models.Model): qty_onhand = check_qty_per_inventory(self, line.product_id, line.location_id) if line.qty_done > qty_onhand: - raise UserError('Quantity Done melebihi Quantity Onhand') + raise UserError(f'{line.product_id.display_name} : Quantity Done melebihi Quantity Onhand') def button_validate(self): if not self.env.user.is_logistic_approver and self.env.context.get('active_model') == 'stock.picking': -- cgit v1.2.3