summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-20 15:06:17 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-20 15:06:17 +0700
commit79bf9729d10c8fb37ef9071ab6df2b6644ddea49 (patch)
tree6226da5e38ad44673a1bb5d7d4e2b0fd5df1fada /indoteknik_custom/models/sale_order.py
parenteb7661705303a64c97e84061b53d48d5c46f6293 (diff)
parentd2bb21ae878db2a3b77dbb3341046c9d12ba1de5 (diff)
Merge branch 'production' into iman/new-register
# Conflicts: # indoteknik_custom/models/res_users.py
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py96
1 files changed, 95 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 16a1f415..aa5443c5 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')
@@ -109,6 +111,45 @@ 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)
+ voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher Shipping', copy=False)
+ margin_after_delivery_purchase = fields.Float(string='Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase')
+ percent_margin_after_delivery_purchase = fields.Float(string='% Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase')
+ purchase_delivery_amt = fields.Float(string='Purchase Delivery Amount', compute='_compute_purchase_delivery_amount')
+ type_promotion = fields.Char(string='Type Promotion', compute='_compute_type_promotion')
+
+ def _compute_type_promotion(self):
+ for rec in self:
+ promotion_types = []
+ for promotion in rec.order_promotion_ids:
+ for line_program in promotion.program_line_id:
+ if line_program.promotion_type:
+ promotion_types.append(dict(line_program._fields['promotion_type'].selection).get(line_program.promotion_type))
+
+ # Removing duplicates by converting to a set, then back to a list
+ rec.type_promotion = ', '.join(sorted(set(promotion_types)))
+
+ def _compute_purchase_delivery_amount(self):
+ for order in self:
+ match = self.env['purchase.order.sales.match']
+ result2 = match.search([
+ ('sale_id.id', '=', order.id)
+ ])
+ delivery_amt = 0
+ for res in result2:
+ delivery_amt = res.delivery_amt
+ order.purchase_delivery_amt = delivery_amt
+
+ def _compute_margin_after_delivery_purchase(self):
+ for order in self:
+ order.margin_after_delivery_purchase = order.total_margin - order.purchase_delivery_amt
+ if order.amount_untaxed == 0:
+ order.percent_margin_after_delivery_purchase = 0
+ continue
+ if order.shipping_cost_covered == 'indoteknik':
+ delivery_amt = order.delivery_amt
+ else:
+ delivery_amt = 0
+ order.percent_margin_after_delivery_purchase = round((order.margin_after_delivery_purchase / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2)
def _compute_date_kirim(self):
for rec in self:
@@ -630,6 +671,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')
@@ -743,7 +787,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')
@@ -780,6 +824,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:
@@ -821,6 +887,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
@@ -829,6 +918,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)