summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_picking.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-11-29 10:35:39 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-11-29 10:35:39 +0700
commit75cad0da1476a2e605ef5d0f35cfb58944831934 (patch)
tree6cc7e014ef006e8d7794f2b6f50437bef61dd724 /indoteknik_custom/models/stock_picking.py
parentfd5617629243b879e020afbdb2f1957d2e419ae4 (diff)
parentfa3da08e5c0837e1492a3b00b17b7492c07ac676 (diff)
Merge branch 'production' into CR/website-improvment
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
-rw-r--r--indoteknik_custom/models/stock_picking.py85
1 files changed, 52 insertions, 33 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 430c54f3..17dd5766 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -34,7 +34,6 @@ class StockPicking(models.Model):
)
driver_arrival_date = fields.Datetime(
string='Delivery Arrival Date',
- readonly=True,
copy=False
)
delivery_tracking_no = fields.Char(
@@ -281,9 +280,9 @@ class StockPicking(models.Model):
def _compute_shipping_status(self):
for rec in self:
status = 'pending'
- if rec.driver_departure_date and not rec.driver_arrival_date:
+ if rec.driver_departure_date and not (rec.sj_return_date or rec.driver_arrival_date):
status = 'shipment'
- elif rec.driver_departure_date and rec.driver_arrival_date:
+ elif rec.driver_departure_date and (rec.sj_return_date or rec.driver_arrival_date):
status = 'completed'
rec.shipping_status = status
@@ -443,30 +442,31 @@ class StockPicking(models.Model):
for pick in self:
if self.env.user.is_accounting:
pick.approval_return_status = 'approved'
- else:
- if self.picking_type_code == 'outgoing':
- if self.env.user.id in [3988, 3401, 20]:
- action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_stock_return_note_wizard')
- action['context'] = {
- 'picking_ids': [x.id for x in self]
- }
- return action
- elif not self.env.user.id in [3988, 3401, 20] and 'Return of' in self.origin:
- raise UserError('Harus Purchasing yang Ask Return')
- else:
- raise UserError('Harus Sales Admin yang Ask Return')
- elif self.picking_type_code == 'incoming':
- if self.env.user.has_group('indoteknik_custom.group_role_purchasing'):
- action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_stock_return_note_wizard')
- action['context'] = {
- 'picking_ids': [x.id for x in self]
- }
- return action
- elif not self.env.user.has_group('indoteknik_custom.group_role_purchasing') and 'Return of' in self.origin:
- raise UserError('Harus Sales Admin yang Ask Return')
- else:
- raise UserError('Harus Purchasing yang Ask Return')
+ continue
+ action = self.env['ir.actions.act_window']._for_xml_id('indoteknik_custom.action_stock_return_note_wizard')
+
+ if self.picking_type_code == 'outgoing':
+ if self.env.user.id in [3988, 3401, 20] or (
+ self.env.user.has_group('indoteknik_custom.group_role_purchasing') and 'Return of' in self.origin
+ ):
+ action['context'] = {'picking_ids': [x.id for x in self]}
+ return action
+ elif not self.env.user.has_group('indoteknik_custom.group_role_purchasing') and 'Return of' in self.origin:
+ raise UserError('Harus Purchasing yang Ask Return')
+ else:
+ raise UserError('Harus Sales Admin yang Ask Return')
+
+ elif self.picking_type_code == 'incoming':
+ if self.env.user.has_group('indoteknik_custom.group_role_purchasing') or (
+ self.env.user.id in [3988, 3401, 20] and 'Return of' in self.origin
+ ):
+ action['context'] = {'picking_ids': [x.id for x in self]}
+ return action
+ elif not self.env.user.id in [3988, 3401, 20] and 'Return of' in self.origin:
+ raise UserError('Harus Sales Admin yang Ask Return')
+ else:
+ raise UserError('Harus Purchasing yang Ask Return')
def calculate_line_no(self):
@@ -523,12 +523,31 @@ class StockPicking(models.Model):
and quant.inventory_quantity < line.product_uom_qty
):
raise UserError('Quantity reserved lebih besar dari quantity onhand di product')
+
+ def check_qty_done_stock(self):
+ for line in self.move_line_ids_without_package:
+ def check_qty_per_inventory(self, product, location):
+ quant = self.env['stock.quant'].search([
+ ('product_id', '=', product.id),
+ ('location_id', '=', location.id),
+ ])
+ if quant:
+ return quant.quantity
+
+ return 0
+
+ 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')
def button_validate(self):
if not self.env.user.is_logistic_approver and self.env.context.get('active_model') == 'stock.picking':
if self.origin and 'Return of' in self.origin:
raise UserError("Button ini hanya untuk Logistik")
+
+ if self.picking_type_code == 'internal':
+ self.check_qty_done_stock()
if self._name != 'stock.picking':
return super(StockPicking, self).button_validate()
@@ -551,10 +570,10 @@ class StockPicking(models.Model):
if self.location_dest_id.id == 47 and not self.env.user.is_purchasing_manager:
raise UserError("Transfer ke gudang selisih harus di approve Rafly Hanggara")
- if self.group_id.sale_id:
- if self.group_id.sale_id.payment_link_midtrans:
- if self.group_id.sale_id.payment_status != 'settlement':
- raise UserError('Uang belum masuk (settlement), mohon konfirmasi ke sales atau finance')
+ # if self.group_id.sale_id:
+ # if self.group_id.sale_id.payment_link_midtrans:
+ # if self.group_id.sale_id.payment_status != 'settlement' and self.group_id.sale_id.state == 'draft':
+ # raise UserError('Uang belum masuk (settlement), mohon konfirmasi ke sales atau finance')
if self.is_internal_use:
self.approval_status = 'approved'
@@ -657,13 +676,13 @@ class StockPicking(models.Model):
manifest_datas = []
departure_date = self.driver_departure_date
- arrival_date = self.driver_arrival_date
+ arrival_date = self.sj_return_date if self.sj_return_date else self.driver_arrival_date
status = status_mapping.get(status_key)
if not status:
return manifest_datas
- if arrival_date:
+ if arrival_date or self.sj_return_date:
manifest_datas.append(self.create_manifest_data(status['arrival'], arrival_date))
if departure_date:
manifest_datas.append(self.create_manifest_data(status['departure'], departure_date))
@@ -690,7 +709,7 @@ class StockPicking(models.Model):
}
if not self.waybill_id or len(self.waybill_id.manifest_ids) == 0:
- response['delivered'] = self.driver_arrival_date != False
+ response['delivered'] = self.sj_return_date != False or self.driver_arrival_date != False
return response
response['delivery_order']['receiver_name'] = self.waybill_id.receiver_name