summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_picking.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-11-22 09:47:09 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-11-22 09:47:09 +0700
commit14559e52ce09e6e73c220987455c43ce89f9eabf (patch)
treef1376589fe885ef42ea45ab6cb3bc7f71c7d476a /indoteknik_custom/models/stock_picking.py
parent755e36e6fed87f787c2a0d31f4318a6eae97e55c (diff)
parent4e84a3c939f50315c5eba4a9ae350f17383b5543 (diff)
Merge branch 'production' into iman/pengajuan-tempo
# Conflicts: # indoteknik_custom/models/res_partner.py
Diffstat (limited to 'indoteknik_custom/models/stock_picking.py')
-rw-r--r--indoteknik_custom/models/stock_picking.py81
1 files changed, 53 insertions, 28 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 50e9304b..10b26711 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(
@@ -112,6 +111,7 @@ class StockPicking(models.Model):
('done', 'Done'),
('cancel', 'Cancelled'),
], string='Status Reserve', readonly=True, tracking=True, help="The current state of the stock picking.")
+ notee = fields.Text(string="Note")
def action_send_to_biteship(self):
url = "https://api.biteship.com/v1/orders"
@@ -193,9 +193,10 @@ 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):
+ if not self.date_doc_kirim:
+ self.date_doc_kirim = self.driver_departure_date
@api.constrains('arrival_time')
def constrains_arrival_time(self):
@@ -279,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
@@ -441,26 +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
- 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
- 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):
@@ -517,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()
@@ -651,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))
@@ -684,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