summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-09-12 10:35:01 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-09-12 10:35:01 +0700
commit16acaa437f203ccfa52aba132225b2bb82ac1c79 (patch)
treed4ce062668f1f6d2642e5280f979e60d0acf05a0 /indoteknik_custom/models/sale_order.py
parentf03e6dc2ee2f3cd34eca15e81cd8964c07089ef4 (diff)
parenta8e539c92236453ce7aad06d23cf117f4b7239fc (diff)
Merge branch 'production' into unreserved_permission
# Conflicts: # indoteknik_api/controllers/api_v1/cart.py # indoteknik_custom/models/sale_order.py
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py58
1 files changed, 57 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index abfbb799..023cc5e6 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -88,6 +88,8 @@ class SaleOrder(models.Model):
voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False)
applied_voucher_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False)
amount_voucher_disc = fields.Float(string='Voucher Discount')
+ applied_voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False)
+ amount_voucher_shipping_disc = fields.Float(string='Voucher Discount')
source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]", required=True)
estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0)
email = fields.Char(string='Email')
@@ -110,6 +112,7 @@ class SaleOrder(models.Model):
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')
+ voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher Shipping', copy=False)
def do_unreserve(self):
user_id = self.env.user.id
@@ -641,6 +644,9 @@ class SaleOrder(models.Model):
if not order.client_order_ref and order.create_date > datetime(2024, 6, 27):
raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO")
+
+ if not order.commitment_date and order.create_date > datetime(2024, 9, 12):
+ raise UserError("Expected Delivery Date kosong, wajib diisi")
if order.validate_partner_invoice_due():
return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension')
@@ -754,7 +760,7 @@ class SaleOrder(models.Model):
delivery_amt = order.delivery_amt
else:
delivery_amt = 0
- order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt)) * 100, 2)
+ order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2)
# order.total_percent_margin = round((order.total_margin / (order.amount_untaxed)) * 100, 2)
@api.onchange('sales_tax_id')
@@ -791,6 +797,28 @@ class SaleOrder(models.Model):
self.apply_voucher()
+ def action_apply_voucher_shipping(self):
+ for line in self.order_line:
+ if line.order_promotion_id:
+ raise UserError('Voucher tidak dapat digabung dengan promotion program')
+
+ voucher = self.voucher_shipping_id
+ if voucher.limit > 0 and voucher.count_order >= voucher.limit:
+ raise UserError('Voucher tidak dapat digunakan karena sudah habis digunakan')
+
+ partner_voucher_orders = []
+ for order in voucher.order_ids:
+ if order.partner_id.id == self.partner_id.id:
+ partner_voucher_orders.append(order)
+
+ if voucher.limit_user > 0 and len(partner_voucher_orders) >= voucher.limit_user:
+ raise UserError('Voucher tidak dapat digunakan karena Customer ini sudah menghabiskan kuota voucher')
+
+ if self.pricelist_id.id in [x.id for x in voucher.excl_pricelist_ids]:
+ raise UserError('Voucher tidak dapat digunakan karena pricelist ini tidak berlaku pada voucher')
+
+ self.apply_voucher_shipping()
+
def apply_voucher(self):
order_line = []
for line in self.order_line:
@@ -832,6 +860,29 @@ class SaleOrder(models.Model):
self.amount_voucher_disc = voucher['discount']['all']
self.applied_voucher_id = self.voucher_id
+ def apply_voucher_shipping(self):
+ for order in self:
+ delivery_amt = order.delivery_amt
+ voucher = order.voucher_shipping_id
+
+ if voucher:
+ max_discount_amount = voucher.discount_amount
+ voucher_type = voucher.discount_type
+
+ if voucher_type == 'fixed_price':
+ discount = max_discount_amount
+ elif voucher_type == 'percentage':
+ discount = delivery_amt * (max_discount_amount / 100)
+
+ delivery_amt -= discount
+
+ delivery_amt = max(delivery_amt, 0)
+
+ order.delivery_amt = delivery_amt
+
+ order.amount_voucher_shipping_disc = discount
+ order.applied_voucher_shipping_id = order.voucher_id.id
+
def cancel_voucher(self):
self.applied_voucher_id = False
self.amount_voucher_disc = 0
@@ -840,6 +891,11 @@ class SaleOrder(models.Model):
line.discount = line.initial_discount
line.initial_discount = False
+ def cancel_voucher_shipping(self):
+ self.delivery_amt + self.amount_voucher_shipping_disc
+ self.applied_voucher_shipping_id = False
+ self.amount_voucher_shipping_disc = 0
+
def action_web_approve(self):
if self.env.uid != self.partner_id.user_id.id:
raise UserError('You are not authorized to approve this order. Only %s can approve this order.' % self.partner_id.user_id.name)