From 9ee856d603530e8cc3494a2bccb8fdfaa328da6a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 14:14:09 +0700 Subject: push --- indoteknik_api/controllers/api_v1/cart.py | 23 +++++++++++++++++++---- indoteknik_custom/models/sale_order.py | 9 +++++++++ indoteknik_custom/models/stock_picking.py | 19 +++++++++++++++++-- indoteknik_custom/views/sale_order.xml | 5 +++++ 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index f472a9b0..a2fd6286 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -17,10 +17,25 @@ class Cart(controller.Controller): query = [('user_id', '=', user_id)] carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc') carts.write({'source': 'add_to_cart'}) - data = { - 'product_total': user_cart.search_count(query), - 'products': carts.with_context(price_for="web").get_products() - } + data = [] + 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: + data.append({ + 'products': cart.with_context(price_for="web").get_products() + }) + else: + data.append({ + 'product_inactive': cart.with_context(price_for="web").get_products() + }) + else: + data.append({ + 'products': cart.with_context(price_for="web").get_products() + }) + data.append({ + 'product_total': user_cart.search_count(query) + }) return self.response(data) @http.route(PREFIX_USER + 'cart/count', auth='public', methods=['GET', 'OPTIONS']) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 710e99de..2769d408 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -109,6 +109,15 @@ class SaleOrder(models.Model): date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False) note_website = fields.Char(string="Note Website") use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) + unreserve_id = fields.Many2one('stock.picking', 'Unreserve Picking') + + def do_unreserve(self): + user_id = self.env.user.id + if user_id != self.user_id.id: + raise UserError(_("Only the user who created the picking can unreserve it.")) + + self.unreserve_id.do_unreserve() + def _compute_date_kirim(self): for rec in self: diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index d16d508e..474c7526 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -125,12 +125,27 @@ class StockPicking(models.Model): raise UserError('Hanya Logistic yang bisa mengubah shipping method') def do_unreserve(self): + if self.sale_id.unreserve_id.id != self.id: + self.sale_id.unreserve_id = self.id + return self._create_approval_notification('Logistic') + res = super(StockPicking, self).do_unreserve() - if not self.env.user.is_purchasing_manager: - raise UserError('Hanya Purchasing Manager yang bisa Unreserve') current_time = datetime.datetime.utcnow() self.date_unreserve = current_time + return res + + def _create_approval_notification(self, approval_role): + title = 'Warning' + message = f'Butuh approval sales untuk unreserved' + return self._create_notification_action(title, message) + + def _create_notification_action(self, title, message): + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { 'title': title, 'message': message, 'next': {'type': 'ir.actions.act_window_close'} }, + } def _compute_shipping_status(self): for rec in self: diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 1257ff85..569c59f3 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -11,6 +11,10 @@ string="Create No" type="object" /> +