From 3b1c519848d69709aa64ff6078c7d2d45dc356b1 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Wed, 6 Nov 2024 16:46:40 +0700 Subject: bugfix date time --- indoteknik_api/controllers/api_v1/stock_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/stock_picking.py b/indoteknik_api/controllers/api_v1/stock_picking.py index f0c7456d..ea8c6400 100644 --- a/indoteknik_api/controllers/api_v1/stock_picking.py +++ b/indoteknik_api/controllers/api_v1/stock_picking.py @@ -123,7 +123,7 @@ class StockPicking(controller.Controller): params = {'sj_documentation': sj_document, 'paket_documentation': paket_document, - 'driver_arrival_date': self.time_to_str(datetime.utcnow(), '%Y-%m-%d %H:%M:%S'), + 'driver_arrival_date': datetime.utcnow(), } picking_data = request.env['stock.picking'].search([('picking_code', '=', picking_code)], limit=1) -- cgit v1.2.3 From ca625dc60de8bbf53e21326abc24c210ea0f8f71 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 7 Nov 2024 11:51:13 +0700 Subject: cr archive and unpublished product variant --- indoteknik_custom/models/product_template.py | 49 ++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 2ca4925b..e64b63d7 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -389,23 +389,46 @@ class ProductProduct(models.Model): @api.constrains('active') def archive_product(self): for product in self: + if self.env.context.get('skip_unpublished_constraint'): + continue # Mencegah looping saat dipanggil dari metode lain + product_template = product.product_tmpl_id variants = product_template.product_variant_ids - if product_template.active and product.active: - if not product.active and len(variants) == 1: - product_template.with_context(skip_active_constraint=True).active = False - product_template.unpublished = True - elif not product.active and len(variants) > 1: + if len(variants) == 1: + # Jika hanya ada satu varian, atur status `unpublished` berdasarkan `active` + product_template.with_context(skip_unpublished_constraint=True).unpublished = not product.active + product.with_context(skip_unpublished_constraint=True).unpublished = not product.active + else: + if product.active: + product.with_context(skip_unpublished_constraint=True).unpublished = False + product_template.with_context(skip_unpublished_constraint=True).unpublished = any(variant.active for variant in variants) + else: + product.with_context(skip_unpublished_constraint=True).unpublished = True all_inactive = all(not variant.active for variant in variants) - if all_inactive: - product_template.with_context(skip_active_constraint=True).active = False - product_template.unpublished = True - else: - continue - if any(variant.active for variant in variants): - product_template.unpublished = False - variants.unpublished = False + product_template.with_context(skip_unpublished_constraint=True).unpublished = all_inactive + + @api.constrains('unpublished') + def archive_product_unpublished(self): + for product in self: + if self.env.context.get('skip_active_constraint'): + continue # Mencegah looping saat dipanggil dari metode lain + + product_template = product.product_tmpl_id + variants = product_template.product_variant_ids + + if len(variants) == 1: + # Jika hanya ada satu varian, atur status `unpublished` pada template, tetapi biarkan `active` tetap True + product_template.with_context(skip_active_constraint=True).unpublished = product.unpublished + else: + if not product.unpublished: + # Jika `unpublished` adalah False, pastikan `active` tetap True + product.with_context(skip_active_constraint=True).active = True + product_template.with_context(skip_active_constraint=True).active = any(not variant.unpublished for variant in variants) + else: + # Jika `unpublished` adalah True, atur template hanya jika semua varian di-unpublished + all_unpublished = all(variant.unpublished for variant in variants) + product_template.with_context(skip_active_constraint=True).active = not all_unpublished def update_internal_reference_variants(self, limit=100): variants = self.env['product.product'].search([ -- cgit v1.2.3 From 0e87cd50902756c86c975505a7dde2239d94968c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 7 Nov 2024 13:47:35 +0700 Subject: bug fix wrong price in website user cart --- indoteknik_custom/models/website_user_cart.py | 41 +++++++++------------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index fbcb0aa4..2142dada 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -93,45 +93,32 @@ class WebsiteUserCart(models.Model): def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) - + if source == 'buy': source = ['buy'] else: source = ['add_to_cart', 'buy'] parameters = [ - ('user_id', '=', user_id), + ('user_id', '=', user_id), ('source', 'in', source) ] - - if selected: - parameters.append(('is_selected', '=', True)) - carts = self.search(parameters) - products_active = [] - products_inactive = [] + for cart in carts: if cart.product_id: price = cart.product_id._v2_get_website_price_include_tax() - if cart.product_id.active and price > 0: - product = cart.with_context(price_for="web").get_products() - for product_active in product: - products_active.append(product_active) - else: - product_inactives = cart.with_context(price_for="web").get_products() - for inactives in product_inactives: - products_inactive.append(inactives) - else: - program = cart.with_context(price_for="web").get_products() - for programs in program: - products_active.append(programs) - data = { - 'product_total': self.search_count(parameters), - 'products': products_active, - 'products_inactive': products_inactive - } - products = carts.get_products() - return products_active + if not cart.product_id.active and price < 1: + cart.is_selected = False + + if selected: + parameters.append(('is_selected', '=', True)) + + products_active = self.search(parameters) + + products = products_active.get_products() + + return products def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): products = self.get_product_by_user(user_id=user_id, selected=True, source=source) -- cgit v1.2.3 From 779002da16637df255b7f8ead65ccb49078d6190 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 7 Nov 2024 13:57:38 +0700 Subject: bf --- indoteknik_custom/models/website_user_cart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 2142dada..6cb282f8 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -108,7 +108,7 @@ class WebsiteUserCart(models.Model): for cart in carts: if cart.product_id: price = cart.product_id._v2_get_website_price_include_tax() - if not cart.product_id.active and price < 1: + if not cart.product_id.active or price < 1: cart.is_selected = False if selected: -- cgit v1.2.3 From 9c54bae83c5fc50d2ca894a7e75d9beb156d3e9c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 7 Nov 2024 16:13:00 +0700 Subject: must link with matches so if want to skip approval --- indoteknik_custom/models/purchase_order.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 6fc0c497..ef86bc61 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -595,7 +595,7 @@ class PurchaseOrder(models.Model): if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser') and not self.env.user.is_leader: raise UserError("Beda Margin dengan Sales, harus approval Merchandise") if not self.from_apo: - if not self.sale_order_id and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser') and not self.env.user.is_leader: + if not self.matches_so and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser') and not self.env.user.is_leader: raise UserError("Tidak ada link dengan SO, harus approval Merchandise") send_email = False @@ -727,7 +727,7 @@ class PurchaseOrder(models.Model): raise UserError("Hanya Merchandiser yang bisa approve") if self.env.user.is_leader or self.env.user.has_group('indoteknik_custom.group_role_merchandiser'): raise UserError("Bisa langsung Confirm") - elif self.total_percent_margin == self.total_so_percent_margin and self.sale_order_id: + elif self.total_percent_margin == self.total_so_percent_margin and self.matches_so: raise UserError("Bisa langsung Confirm") else: reason = '' @@ -736,12 +736,14 @@ class PurchaseOrder(models.Model): reason = 'above 50jt, ' if self.total_percent_margin < self.total_so_percent_margin: reason += 'diff margin, ' - if not self.from_apo and not self.sale_order_id: - reason += 'not link with sales, ' + if not self.from_apo and not self.matches_so: + reason += 'not link with pj and reorder, ' + if not self.matches_so: + reason += 'not link with so, ' # Post a highlighted message to lognote self.message_post( body=f"
" - f"Note Return (Pinned):
{reason}
", + f"Note (Pinned):
{reason}", subtype_id=self.env.ref("mail.mt_note").id ) -- cgit v1.2.3 From 8d4ba8a22aa90a7c2dfad48c5de38ee17b68db60 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 7 Nov 2024 16:21:20 +0700 Subject: deactivate function constrains driver departure date date doc kirim --- indoteknik_custom/models/stock_picking.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 4c9d7658..a4031d52 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -192,9 +192,9 @@ class StockPicking(models.Model): else: raise UserError(f"Error saat mengirim ke Biteship: {response.content}") - @api.constrains('driver_departure_date') - def constrains_driver_departure_date(self): - self.date_doc_kirim = self.driver_departure_date + # @api.constrains('driver_departure_date') + # def constrains_driver_departure_date(self): + # self.date_doc_kirim = self.driver_departure_date @api.constrains('arrival_time') def constrains_arrival_time(self): -- cgit v1.2.3 From 02e7b5f913c4f740124d28c078c4f6f1185d9b0f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 8 Nov 2024 11:12:06 +0700 Subject: cr sj return date do --- indoteknik_custom/models/delivery_order.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/delivery_order.py b/indoteknik_custom/models/delivery_order.py index 2ed49a54..3473197b 100644 --- a/indoteknik_custom/models/delivery_order.py +++ b/indoteknik_custom/models/delivery_order.py @@ -33,11 +33,13 @@ class DeliveryOrder(models.TransientModel): picking.driver_id = self.env.uid picking.delivery_tracking_no = line_tracking_no + if picking.driver_departure_date: + picking.sj_return_date = datetime.utcnow() + delivery_type = self.env['delivery.order.line'].get_delivery_type(picking.driver_departure_date, picking.driver_arrival_date) if delivery_type == 'departure': picking.driver_departure_date = current_time elif delivery_type == 'arrival': - picking.sj_return_date = datetime.utcnow() sale_order = False if picking.origin: -- cgit v1.2.3 From 1d7d90b35078c82ed1904bfb4486e172488bf747 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 8 Nov 2024 14:08:10 +0700 Subject: cr function state reserve transfer --- indoteknik_custom/models/stock_picking.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index a4031d52..1906dae0 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -246,25 +246,22 @@ class StockPicking(models.Model): # break def check_state_reserve(self): - picking = self.search([ + pickings = self.search([ ('state', 'not in', ['cancel', 'draft', 'done']), ('picking_type_code', '=', 'outgoing') - ]) + ]) - for data in picking: - fullfilment = self.env['sales.order.fullfillment'].search([ - ('sales_order_id', '=', data.sale_id.id) + for picking in pickings: + fullfillments = self.env['sales.order.fullfillment'].search([ + ('sales_order_id', '=', picking.sale_id.id) ]) - - data.state_reserve = 'ready' - if not data.date_reserved: - data.date_reserved = datetime.datetime.utcnow() - - for rec in fullfilment: - if rec.reserved_from not in ['Inventory On Hand', 'Reserved from stock', 'Free Stock']: - data.state_reserve = 'waiting' - data.date_reserved = '' - break + + picking.state_reserve = 'ready' + picking.date_reserved = picking.date_reserved or datetime.datetime.utcnow() + + if any(rec.reserved_from not in ['Inventory On Hand', 'Reserved from stock', 'Free Stock'] for rec in fullfillments): + picking.state_reserve = 'waiting' + picking.date_reserved = '' def _create_approval_notification(self, approval_role): title = 'Warning' -- cgit v1.2.3 From 8423e5b2facd32aec17ac67d95ffc83e7bc311b7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 8 Nov 2024 15:39:37 +0700 Subject: cr vendor approval --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 8e170b1c..5545e28c 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,7 +78,7 @@ class SaleOrder(models.Model): payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') payment_qr_code = fields.Binary("Payment QR Code") due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) - vendor_approval_id = fields.Many2one('vendor.approval', string="Vendor Approval", readonly=True, tracking=True) + vendor_approval_id = fields.Many2one('vendor.approval', string="Vendor Approval", readonly=True, tracking=True, copy=False) customer_type = fields.Selection([ ('pkp', 'PKP'), ('nonpkp', 'Non PKP') -- cgit v1.2.3 From 5a53288558a0adf7bff223f745be75cf48cb252f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 8 Nov 2024 16:16:04 +0700 Subject: fix bug approval date doc --- indoteknik_custom/models/approval_date_doc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py index 441ada3d..751bae82 100644 --- a/indoteknik_custom/models/approval_date_doc.py +++ b/indoteknik_custom/models/approval_date_doc.py @@ -40,6 +40,7 @@ class ApprovalDateDoc(models.Model): raise UserError("Hanya Accounting Yang Bisa Approve") self.check_invoice_so_picking self.picking_id.driver_departure_date = self.driver_departure_date + self.picking_id.date_doc_kirim = self.driver_departure_date self.state = 'done' self.approve_date = datetime.utcnow() self.approve_by = self.env.user.id -- cgit v1.2.3 From de1fa6223484ea424ae9b6bcf3f3fedf75ae6bb1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 11 Nov 2024 10:11:59 +0700 Subject: fix vendor approval bug --- indoteknik_custom/models/sale_order_line.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 5e01067a..f218757b 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -251,12 +251,9 @@ class SaleOrderLine(models.Model): # purchase_price = self.env['purchase.pricelist'].search( # query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc') price, taxes, vendor_id = self._get_purchase_price(line.product_id) - line.vendor_md_id = vendor_id line.vendor_id = vendor_id - line.margin_md = line.item_percent_margin line.tax_id = line.order_id.sales_tax_id # price, taxes = line._get_valid_purchase_price(purchase_price) - line.purchase_price_md = price line.purchase_price = price line.purchase_tax_id = taxes @@ -270,6 +267,14 @@ class SaleOrderLine(models.Model): line.name = line_name line.weight = line.product_id.weight + @api.constrains('vendor_id') + def _check_vendor_id(self): + for line in self: + price, taxes, vendor_id = self._get_purchase_price(line.product_id) + line.vendor_md_id = vendor_id + line.margin_md = line.item_percent_margin + line.purchase_price_md = price + def compute_delivery_amt_line(self): for line in self: try: -- cgit v1.2.3 From 20060408d381fddf859d3e99ee9dcdd187ac1329 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 11 Nov 2024 10:30:56 +0700 Subject: fix bug --- 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 f218757b..fe6d9b8c 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -271,7 +271,7 @@ class SaleOrderLine(models.Model): def _check_vendor_id(self): for line in self: price, taxes, vendor_id = self._get_purchase_price(line.product_id) - line.vendor_md_id = vendor_id + line.vendor_md_id = vendor_id if vendor_id else '' line.margin_md = line.item_percent_margin line.purchase_price_md = price -- cgit v1.2.3 From 3404e2526fd4d95fc93224fbcfb5ddbfd254dcb5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 11 Nov 2024 10:37:35 +0700 Subject: fix bug vendor md --- 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 fe6d9b8c..978b1f69 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -271,7 +271,7 @@ class SaleOrderLine(models.Model): def _check_vendor_id(self): for line in self: price, taxes, vendor_id = self._get_purchase_price(line.product_id) - line.vendor_md_id = vendor_id if vendor_id else '' + line.vendor_md_id = vendor_id if vendor_id else None line.margin_md = line.item_percent_margin line.purchase_price_md = price -- cgit v1.2.3 From 3c5b4bbecca6614c0b6f894e41e9551793957b00 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 11 Nov 2024 13:24:11 +0700 Subject: bug fix match requisition and purchase order --- indoteknik_custom/models/requisition.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index c4104ec5..92b222a8 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -108,6 +108,13 @@ class Requisition(models.Model): new_po_line = self.env['purchase.order.line'].create([param_line]) line.current_po_id = new_po.id line.current_po_line_id = new_po_line.id + + self.env['requisition.purchase.match'].create([{ + 'requisition_id': self.id, + 'order_id': new_po.id + }]) + self.is_po = True + return po_ids # def create_po_from_requisition(self): -- cgit v1.2.3 From c8359019759d78dcddea6d419c4a8f8eebe23c69 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 11 Nov 2024 13:27:04 +0700 Subject: validasi SO harus diisi pada saat create PO di requisition --- indoteknik_custom/models/requisition.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 92b222a8..576857df 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -35,6 +35,8 @@ class Requisition(models.Model): raise UserError('Tidak ada Lines, belum bisa create PO') if self.is_po: raise UserError('Sudah pernah di create PO') + if self.sale_order_id: + raise UserError('Tidak ada link dengan Sales Order, tidak bisa dihitung sebagai Plafon Qty di PO') vendor_ids = self.env['requisition.line'].read_group([ ('requisition_id', '=', self.id), -- cgit v1.2.3 From beefbce9a41d0210582cf8ceb6e4e7a6a5bc8fef Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 11 Nov 2024 13:41:46 +0700 Subject: add view of requisition match po --- indoteknik_custom/models/requisition.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 576857df..e5053d34 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -1,4 +1,4 @@ -from odoo import models, fields, api, _ +from odoo import models, fields, api, tools, _ from odoo.exceptions import UserError from datetime import datetime import math @@ -7,6 +7,30 @@ import logging _logger = logging.getLogger(__name__) +class RequisitionMatchPO(models.Model): + _name = 'v.requisition.match.po' + _auto = False + _rec_name = 'purchase_id' + + id = fields.Integer(string='ID') + requisition_id = fields.Many2one('requisition', string='Requisition') + line_id = fields.Many2one('requisition.line', string='Requisition Line') + product_id = fields.Many2one('product.product', string='Product') + partner_id = fields.Many2one('res.partner', string='Partner') + purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + create or replace view %s as + select rpm.id as id, r.id as requisition_id, rl.id as line_id, rl.product_id, rl.partner_id, + rpm.order_id as purchase_id + from requisition_line rl + join requisition r on r.id = rl.requisition_id + join requisition_purchase_match rpm on rpm.requisition_id = r.id + """ % self._table) + + class Requisition(models.Model): _name = 'requisition' _order = 'id desc' -- cgit v1.2.3 From 03e9f9e8997836e37a5ab38798edb310ce6a6c76 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 11 Nov 2024 13:43:48 +0700 Subject: add sale order --- indoteknik_custom/models/requisition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index e5053d34..68c57e4c 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -24,7 +24,7 @@ class RequisitionMatchPO(models.Model): self.env.cr.execute(""" create or replace view %s as select rpm.id as id, r.id as requisition_id, rl.id as line_id, rl.product_id, rl.partner_id, - rpm.order_id as purchase_id + rpm.order_id as purchase_id, r.sale_order_id as sale_id from requisition_line rl join requisition r on r.id = rl.requisition_id join requisition_purchase_match rpm on rpm.requisition_id = r.id -- cgit v1.2.3 From e40f5a21ec251363b3b71d81b7801a782716ca0a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 11 Nov 2024 13:43:58 +0700 Subject: add approval sales manager and marketing manager on rpo --- indoteknik_custom/models/requisition.py | 17 ++++++++++++++++- indoteknik_custom/views/requisition.xml | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index c4104ec5..e09c9e41 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -22,15 +22,30 @@ class Requisition(models.Model): requisition_match = fields.One2many('requisition.purchase.match', 'requisition_id', string='Matches', auto_join=True) sale_order_id = fields.Many2one('sale.order', string='SO', help='harus diisi nomor SO yang ingin digenerate', domain="[('state', '=', 'sale')]") + sales_approve = fields.Boolean(string='Sales Approve', tracking=3, copy=False) + merchandise_approve = fields.Boolean(string='Merchandise Approve', tracking=3, copy=False) @api.model def create(self, vals): vals['number'] = self.env['ir.sequence'].next_by_code('requisition') or '0' result = super(Requisition, self).create(vals) return result - + + def button_approve(self): + if self.env.user.id not in [377, 19]: + raise UserError('Hanya Vita dan Darren Yang Bisa Approve') + if self.env.user.id == 377: + self.sales_approve = True + elif self.env.user.id == 19: + if not self.sales_approve: + raise UserError('Vita Belum Approve') + self.merchandise_approve = True def create_po_from_requisition(self): + if not self.sales_approve: + raise UserError('Harus di Approve Vita') + if not self.merchandise_approve: + raise UserError('Harus di Approve Darren') if not self.requisition_lines: raise UserError('Tidak ada Lines, belum bisa create PO') if self.is_po: diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml index b704baaf..a866690d 100644 --- a/indoteknik_custom/views/requisition.xml +++ b/indoteknik_custom/views/requisition.xml @@ -50,6 +50,13 @@ requisition
+
+
-- cgit v1.2.3 From e573a766b997e4dc60935f8cc87e887d09f64b7a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 11 Nov 2024 13:53:22 +0700 Subject: add sale order condition in match requisition --- indoteknik_custom/models/requisition.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 68c57e4c..583a25c4 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -28,6 +28,11 @@ class RequisitionMatchPO(models.Model): from requisition_line rl join requisition r on r.id = rl.requisition_id join requisition_purchase_match rpm on rpm.requisition_id = r.id + join purchase_order po on po.id = rpm.order_id + join sale_order so on so.id = r.sale_order_id + where r.date_doc >= '2024-11-11' + and po.state in ('done', 'purchase') + and so.state in ('draft', 'sent') """ % self._table) -- cgit v1.2.3 From 9a0fd25e54491bd14a5b29b62b31a440dfa1bebc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 11 Nov 2024 14:10:13 +0700 Subject: change view requisition match --- indoteknik_custom/models/requisition.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 0ab78530..704ae8c0 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -13,26 +13,24 @@ class RequisitionMatchPO(models.Model): _rec_name = 'purchase_id' id = fields.Integer(string='ID') - requisition_id = fields.Many2one('requisition', string='Requisition') - line_id = fields.Many2one('requisition.line', string='Requisition Line') product_id = fields.Many2one('product.product', string='Product') - partner_id = fields.Many2one('res.partner', string='Partner') - purchase_id = fields.Many2one('purchase.order', string='Purchase Order') + qty_rpo = fields.Float(string='Qty RPO', help='Qty RPO yang sudah di PO namun SO masih Draft') def init(self): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" create or replace view %s as - select rpm.id as id, r.id as requisition_id, rl.id as line_id, rl.product_id, rl.partner_id, - rpm.order_id as purchase_id, r.sale_order_id as sale_id + select rl.product_id as id, rl.product_id, sum(rl.qty_purchase) as qty_rpo from requisition_line rl join requisition r on r.id = rl.requisition_id join requisition_purchase_match rpm on rpm.requisition_id = r.id join purchase_order po on po.id = rpm.order_id join sale_order so on so.id = r.sale_order_id - where r.date_doc >= '2024-11-11' + where 1=1 + and r.date_doc >= '2024-11-11' and po.state in ('done', 'purchase') and so.state in ('draft', 'sent') + group by rl.product_id """ % self._table) -- cgit v1.2.3