summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-09-22 13:46:48 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-09-22 13:46:48 +0700
commit60fffef5ee0c91ba58a056823fc2feff6241a303 (patch)
tree9135ec67b5f509d74787e8869d4b11b60e39d7fb /indoteknik_custom/models/purchase_order.py
parentb5c15f8ee9171ade6f3d11415a383b0a9f936110 (diff)
add calculate margin including delivery fee in purchase order
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index cb048182..fd02cd2b 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -5,7 +5,20 @@ class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
sale_order_id = fields.Many2one('sale.order', string='Sale Order')
- procurement_status = fields.Char(string='Procurement Status', compute='get_procurement_status',readonly=True)
+ procurement_status = fields.Char(string='Procurement Status', compute='get_procurement_status', readonly=True)
+ total_margin = fields.Float(
+ 'Total Margin', compute='compute_total_margin',
+ help="Total Margin in Sales Order Header")
+ total_percent_margin = fields.Float(
+ 'Total Percent Margin', compute='compute_total_margin',
+ help="Total % Margin in Sales Order Header")
+ approval_status = fields.Selection([
+ ('pengajuan1', 'Approval Manager'), #siapa?
+ ('pengajuan2', 'Approval Pimpinan'), #akbar
+ ('approved', 'Approved'),
+ ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
+ count_line_product = fields.Float('Count Line Product', compute='compute_count_line_product')
+ delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount')
def get_procurement_status(self):
for purchase_order in self:
@@ -44,3 +57,38 @@ class PurchaseOrder(models.Model):
}
self.env['purchase.order.line'].sudo().create(values)
+ def compute_count_line_product(self):
+ for order in self:
+ count = 0
+ for line in order.order_line:
+ if line.product_id.type == 'product':
+ count += 1
+ if count == 0:
+ order.count_line_product = 1
+ else:
+ order.count_line_product = count
+
+ def compute_delivery_amount(self):
+ for order in self:
+ amount = 0
+ for line in order.order_line:
+ if line.product_id.type == 'service':
+ amount += line.price_total
+ order.delivery_amount = amount
+
+ def compute_total_margin(self):
+ for po in self:
+ po.total_margin = 0
+ po.total_percent_margin = 0
+ for po in self:
+ total_margin = total_percent_margin = 0
+ for line in po.order_line:
+ if not line.product_id:
+ po.total_margin = 0
+ po.total_percent_margin = 0
+ continue
+ total_margin += line.item_margin
+ po.total_margin = total_margin
+ if po.amount_untaxed > 0:
+ total_percent_margin = round((total_margin / po.amount_untaxed), 2) * 100
+ po.total_percent_margin = total_percent_margin