summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-01-15 13:43:57 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-01-15 13:43:57 +0700
commit4ad4ee17e29d9583b1d2da76af93a1c28fbc8874 (patch)
tree41089526315449d804a7c6e3ae8da7cfd9d5d1e9
parent1780b3327ae4d1227cc0a8238be66f5e64ffcbc1 (diff)
push po line fix bug
-rwxr-xr-xindoteknik_custom/models/purchase_order_line.py74
1 files changed, 73 insertions, 1 deletions
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
index 9e7d7e81..587a09a1 100755
--- a/indoteknik_custom/models/purchase_order_line.py
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -43,7 +43,79 @@ class PurchaseOrderLine(models.Model):
qty_reserved = fields.Float(string='Qty Reserved', compute='_compute_qty_reserved')
delete_line = fields.Boolean(string='Delete', default=False, help='centang ini jika anda ingin menghapus line ini')
is_edit_product_qty = fields.Boolean(string='Is Edit Product Qty', compute='_compute_is_edit_product_qty')
-
+ delivery_amt = fields.Float(string='Delivery Amt', compute='_compute_doc_delivery_amt')
+ delivery_amt_per_item = fields.Float(string='Delivery Amt Per Item' , compute='_compute_doc_delivery_amt')
+ contribution_delivery_amt = fields.Float(string='Contribution Delivery Amt', compute='_compute_doc_delivery_amt')
+ cost_service = fields.Float(string='Biaya Jasa', compute='_compute_doc_delivery_amt')
+ cost_service_per_item = fields.Float(string='Biaya Jasa Per Item', compute='_compute_doc_delivery_amt')
+ contribution_cost_service = fields.Float(string='Contribution Cost Service', compute='_compute_doc_delivery_amt')
+ ending_price = fields.Float(string='Ending Price', compute='_compute_doc_delivery_amt')
+
+ def _compute_doc_delivery_amt(self):
+ for line in self:
+ # Inisialisasi nilai default untuk field computed
+ line.delivery_amt = 0.0
+ line.delivery_amt_per_item = 0.0
+ line.contribution_delivery_amt = 0.0
+ line.cost_service = 0.0
+ line.cost_service_per_item = 0.0
+ line.contribution_cost_service = 0.0
+ line.ending_price = line.price_unit * line.product_qty
+
+ # Ambil nilai dari order_id
+ total_delivery_amt = line.order_id.total_delivery_amt
+ total_cost_service = line.order_id.total_cost_service
+
+ include_price = line.price_unit * line.product_qty
+ if line.order_id.amount_total > 0:
+ if total_delivery_amt > 0:
+ contributions = include_price / line.order_id.amount_total
+ if line.taxes_id.id == 22:
+ contributions = line.price_subtotal / line.order_id.amount_untaxed
+ contribution = contributions * total_delivery_amt
+ line.delivery_amt = contribution
+ line.delivery_amt_per_item = contribution / line.product_qty
+ line.contribution_delivery_amt = contributions
+
+ if total_cost_service > 0:
+ contributions = include_price / line.order_id.amount_total
+ if line.taxes_id.id == 22:
+ contributions = line.price_subtotal / line.order_id.amount_untaxed
+ contribution = contributions * total_cost_service
+ line.cost_service = contribution
+ line.cost_service_per_item = contribution / line.product_qty
+ line.contribution_cost_service = contributions
+
+ if total_delivery_amt > 0 and total_cost_service > 0:
+ line.ending_price = (line.price_unit + line.delivery_amt_per_item + line.cost_service_per_item) * line.product_qty
+ elif total_delivery_amt > 0 and total_cost_service == 0:
+ line.ending_price = (line.price_unit + line.delivery_amt_per_item) * line.product_qty
+ elif total_delivery_amt == 0 and total_cost_service > 0:
+ line.ending_price = (line.price_unit + line.cost_service_per_item) * line.product_qty
+
+ # @api.constrains('delivery_amt')
+ # def delivery_amt_margin(self):
+ # for line in self:
+ # if line.delivery_amt:
+ # line.delivery_amt_per_item = line.delivery_amt / line.product_qty
+ # line.ending_price = line.price_unit + line.delivery_amt_per_item + line.cost_service
+ # elif line.delivery_amt == 0:
+ # line. delivery_amt_per_item = 0
+ # if line.cost_service:
+ # line.ending_price = line.price_unit + line.cost_service
+ # else:
+ # line.ending_price = line.price_unit
+
+ # @api.constrains('cost_service')
+ # def cost_service_margin(self):
+ # for line in self:
+ # if line.cost_service:
+ # line.ending_price = line.price_unit + line.cost_service + line.delivery_amt_per_item
+ # elif line.cost_service == 0:
+ # if line.delivery_amt_per_item:
+ # line.ending_price = line.price_unit + line.delivery_amt_per_item
+ # else:
+ # line.ending_price = line.price_unit
def _get_clean_website_description_product(self):
for line in self:
description = line.product_id.website_description