summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-09-12 14:17:36 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-09-12 14:17:36 +0700
commita37bc839612b5162b4446182ac23c1dfd1c3253e (patch)
tree6dc7020025cf6eeaea6bc86ce591fd269f34d0de /indoteknik_custom/models/sale_order.py
parenta8e539c92236453ce7aad06d23cf117f4b7239fc (diff)
calculate margin after purchase delivery deduction
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 9506aedb..9a6dbd9e 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -112,6 +112,32 @@ class SaleOrder(models.Model):
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')
+
+ 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.total_percent_margin = 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: