summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-09-19 11:07:17 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-09-19 11:07:17 +0700
commitde08a79ca870602ec45f396a8476cfdc3c38aee6 (patch)
treeb92fb1affefe2579a87edd195fe34f2d8c1ca50d /indoteknik_custom/models
parent68cb8eaa625b9c96de7aeb9fc45c1db81921661e (diff)
parentb1c1914eafc652711633f6f11b096a2013cad7e2 (diff)
Merge & fix conflicts
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/delivery_order.py100
-rwxr-xr-xindoteknik_custom/models/sale_order.py1
-rw-r--r--indoteknik_custom/models/stock_picking.py58
4 files changed, 157 insertions, 3 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 6407387c..e4913205 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -23,3 +23,4 @@ from . import blog_post
from . import stock_move
from . import stock_picking
from . import stock_picking_type
+from . import delivery_order
diff --git a/indoteknik_custom/models/delivery_order.py b/indoteknik_custom/models/delivery_order.py
new file mode 100644
index 00000000..06cdd878
--- /dev/null
+++ b/indoteknik_custom/models/delivery_order.py
@@ -0,0 +1,100 @@
+from odoo import models, fields, api
+from odoo.exceptions import UserError
+from pytz import timezone
+from datetime import datetime
+
+
+class DeliveryOrder(models.TransientModel):
+ _name = 'delivery.order'
+
+ name = fields.Char(string='Name', default='Delivery Order')
+ delivery_order_line_ids = fields.One2many(
+ comodel_name='delivery.order.line',
+ inverse_name='delivery_order_id',
+ string='Delivery Order Line'
+ )
+
+ @api.model
+ def create(self, vals):
+ current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+
+ if len(vals['delivery_order_line_ids']) < 1:
+ raise UserError('Delivery Order harus di-isi sebelum melanjutkan')
+
+ for delivery_order_line in vals['delivery_order_line_ids']:
+ picking = False
+ if delivery_order_line[2]['name']:
+ picking = self.env['stock.picking'].search([('picking_code', '=', delivery_order_line[2]['name'])], limit=1)
+
+ if picking:
+ if not picking.driver_id:
+ picking.driver_id = self.env.uid
+ picking.delivery_tracking_no = delivery_order_line[2]['tracking_no']
+
+ 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.driver_arrival_date = current_time
+ return super(DeliveryOrder, self).create(vals)
+
+ def save_delivery(self):
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.client',
+ 'tag': 'display_notification',
+ 'params': {
+ 'title': 'Notification',
+ 'message': 'Delivery Order berhasil disimpan',
+ 'next': {'type': 'ir.actions.act_window_close'},
+ }
+ }
+
+
+class DeliveryOrderLine(models.TransientModel):
+ _name = 'delivery.order.line'
+
+ name = fields.Char(string='DO Number')
+ driver_id = fields.Many2one(comodel_name='res.users', string='Driver')
+ departure_date = fields.Char(string='Departure Date')
+ arrival_date = fields.Char(string='Arrival Date')
+ tracking_no = fields.Char(string='Tracking No')
+ delivery_order_id = fields.Many2one('delivery.order', string='Delivery Order')
+
+ @api.onchange('name')
+ def onchange_name(self):
+ current_time = datetime.now(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S')
+
+ if self.name:
+ if len(self.name) == 13:
+ self.name = self.name[:-1]
+ picking = self.env['stock.picking'].search([('picking_code', '=', self.name)], limit=1)
+ if picking:
+ if picking.driver_id:
+ self.driver_id = picking.driver_id
+ else:
+ self.driver_id = self.env.uid
+
+ self.tracking_no = picking.delivery_tracking_no
+
+ delivery_type = self.get_delivery_type(picking.driver_departure_date, picking.driver_arrival_date)
+ if delivery_type != 'departure':
+ self.departure_date = picking.driver_departure_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S')
+
+ if delivery_type == 'departure':
+ self.departure_date = current_time
+ elif delivery_type == 'arrival':
+ self.arrival_date = current_time
+ else:
+ self.arrival_date = picking.driver_arrival_date.astimezone(timezone('Asia/Jakarta')).strftime('%Y-%m-%d %H:%M:%S')
+ else:
+ raise UserError('Nomor DO tidak ditemukan')
+
+ def get_delivery_type(self, driver_departure_date, driver_arrival_date):
+ delivery_type = 'departure'
+ if driver_departure_date:
+ delivery_type = 'arrival'
+ if driver_arrival_date:
+ delivery_type = False
+
+ return delivery_type
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 57a4921e..1db8a445 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -17,6 +17,7 @@ class SaleOrder(models.Model):
('pengajuan2', 'Approval Tyas'),
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
+ carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method')
have_visit_service = fields.Boolean(string='Have Visit Service', help='To compute is customer get visit service', compute='_compute_have_visit_service')
def _compute_have_visit_service(self):
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 3c39e769..a0b7c15e 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -6,10 +6,37 @@ class StockPicking(models.Model):
_inherit = 'stock.picking'
is_internal_use = fields.Boolean('Internal Use', help='flag which is internal use or not')
account_id = fields.Many2one('account.account', string='Account')
+ efaktur_id = fields.Many2one('vit.efaktur', string='Faktur Pajak')
+ is_efaktur_exported = fields.Boolean(string='Is eFaktur Exported')
+ date_efaktur_exported = fields.Datetime(string='eFaktur Exported Date')
- # efaktur_id = fields.Many2one('vit.efaktur', string='Faktur Pajak')
- # is_efaktur_exported = fields.Boolean(string='Is eFaktur Exported')
- # date_efaktur_exported = fields.Datetime(string='eFaktur Exported Date')
+ # Delivery Order
+ driver_departure_date = fields.Datetime(
+ string='Driver Departure Date',
+ readonly=True,
+ copy=False
+ )
+ driver_arrival_date = fields.Datetime(
+ string='Driver Arrival Date',
+ readonly=True,
+ copy=False
+ )
+ delivery_tracking_no = fields.Char(
+ string='Delivery Tracking Number',
+ readonly=True,
+ copy=False
+ )
+ driver_id = fields.Many2one(
+ comodel_name='res.users',
+ string='Driver',
+ readonly=True,
+ copy=False
+ )
+ picking_code = fields.Char(
+ string="Picking Code",
+ readonly=True,
+ copy=False
+ )
@api.onchange('picking_type_id')
def _onchange_operation_type(self):
@@ -21,3 +48,28 @@ class StockPicking(models.Model):
raise UserError(_('Tidak bisa Validate jika tidak dari Document SO / PO'))
res = super(StockPicking, self).button_validate()
return res
+
+ @api.model
+ def create(self, vals):
+ if not self.picking_code:
+ vals['picking_code'] = self.env['ir.sequence'].next_by_code('stock.picking.code') or '0'
+
+ self._use_faktur(vals)
+ return super(StockPicking, self).create(vals)
+
+ def write(self, vals):
+ self._use_faktur(vals)
+ return super(StockPicking, self).write(vals)
+
+ def _use_faktur(self, vals):
+ if vals.get('efaktur_id', False):
+ self.env['vit.efaktur'].search(
+ [
+ ('id', '=', vals['efaktur_id'])
+ ],
+ limit=1
+ ).is_used = True
+
+ if self.efaktur_id.id != vals['efaktur_id']:
+ self.efaktur_id.is_used = False
+ return True