diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-09-29 19:06:49 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-09-29 19:06:49 +0700 |
| commit | 1e40f3b647d6825779503858bb2ed2d0f8a4b184 (patch) | |
| tree | 79085120f46c7563b8f9c1623a894f3e17889f8e | |
| parent | 156507bd6de73802ae9ef32d344c59184e6f923a (diff) | |
Update purchase_order.py, purchase_order_line.py, and 2 more files...
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 34 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 14 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 11 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 1 |
4 files changed, 43 insertions, 17 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index d51115f8..54ef60af 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -12,7 +12,6 @@ class PurchaseOrder(models.Model): ('pengajuan2', 'Approval Pimpinan'), #akbar - 7 temporary not used ('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') total_margin = fields.Float( 'Margin', compute='compute_total_margin', @@ -26,6 +25,7 @@ class PurchaseOrder(models.Model): total_so_percent_margin = fields.Float( 'SO Margin%', compute='compute_total_margin', help="Total % Margin in Sales Order Header") + amount_total_without_service = fields.Float('AmtTotalWithoutService', compute='compute_amt_total_without_service') def get_procurement_status(self): for purchase_order in self: @@ -64,16 +64,16 @@ 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_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: @@ -171,11 +171,11 @@ class PurchaseOrder(models.Model): sum_so_margin += sale_order_line.item_margin sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': - sales_price -= round((sale_order_line.order_id.delivery_amt / sale_order_line.order_id.count_line_product), 2) + sales_price -= sale_order_line.delivery_amt_line sum_sales_price += sales_price purchase_price = line.price_subtotal if line.order_id.delivery_amount > 0: - purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) + purchase_price += line.delivery_amt_line real_item_margin = sales_price - purchase_price sum_margin += real_item_margin @@ -197,3 +197,11 @@ class PurchaseOrder(models.Model): # return # for line in self.order_line: # line.compute_item_margin() + + def compute_amt_total_without_service(self): + for order in self: + sum_price_total = 0 + for line in order.order_line: + if line.product_id.type == 'product': + sum_price_total += line.price_total + order.amount_total_without_service = sum_price_total diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 19c2c8fa..bd758055 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -17,6 +17,7 @@ class PurchaseOrderLine(models.Model): so_item_percent_margin = fields.Float( 'SO Margin%', compute='compute_item_margin', help="Total % Margin in Sales Order Header") + delivery_amt_line = fields.Float('DeliveryAmtLine', compute='compute_delivery_amt_line') # Override method from addons/purchase/models/purchase.py @api.onchange('product_qty', 'product_uom') @@ -56,13 +57,22 @@ class PurchaseOrderLine(models.Model): sum_so_margin += sale_order_line.item_margin sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': - sales_price -= round((sale_order_line.order_id.delivery_amt / sale_order_line.order_id.count_line_product), 2) + sales_price -= sale_order_line.delivery_amt_line sum_sales_price += sales_price purchase_price = line.price_subtotal if line.order_id.delivery_amount > 0: - purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) + purchase_price += line.delivery_amt_line real_item_margin = sales_price - purchase_price real_item_percent_margin = round((real_item_margin/sales_price), 2) * 100 line.item_margin = real_item_margin line.item_percent_margin = real_item_percent_margin sum_margin += real_item_margin + + def compute_delivery_amt_line(self): + for line in self: + if line.product_id.type == 'product': + contribution = round((line.price_total / line.order_id.amount_total_without_service), 2) + delivery_amt = line.order_id.delivery_amount + line.delivery_amt_line = delivery_amt * contribution + else: + line.delivery_amt_line = 0 diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5c868c67..fda76ebb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -21,7 +21,6 @@ class SaleOrder(models.Model): carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method') have_visit_service = fields.Boolean(string='Have Visit Service', help='To compute is customer get visit service', compute='_compute_have_visit_service') - count_line_product = fields.Float('Count Line Product', compute='compute_count_line_product') delivery_amt = fields.Float('Delivery Amt') shipping_cost_covered = fields.Selection([ ('indoteknik', 'Indoteknik'), @@ -162,6 +161,7 @@ class SaleOrderLine(models.Model): purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0) purchase_tax_id = fields.Many2one('account.tax', string='Tax', domain=['|', ('active', '=', False), ('active', '=', True)]) + delivery_amt_line = fields.Float('DeliveryAmtLine', compute='compute_delivery_amt_line') def compute_item_margin(self): for line in self: @@ -175,7 +175,8 @@ class SaleOrderLine(models.Model): sales_price = line.price_reduce_taxexcl * line.product_uom_qty # minus with delivery if covered by indoteknik if line.order_id.shipping_cost_covered == 'indoteknik': - sales_price -= round((line.order_id.delivery_amt / line.order_id.count_line_product), 2) + sales_price -= line.delivery_amt_line + # sales_price -= round((line.order_id.delivery_amt / line.order_id.count_line_product), 2) purchase_price = line.purchase_price if line.purchase_tax_id.price_include: @@ -205,3 +206,9 @@ class SaleOrderLine(models.Model): [('product_id', '=', self.product_id.id)], limit=1, order='product_price ASC') line.vendor_id = purchase_price.vendor_id line.tax_id = line.order_id.sales_tax_id + + def compute_delivery_amt_line(self): + for line in self: + contribution = round((line.price_total / line.order_id.amount_total), 2) + delivery_amt = line.order_id.delivery_amt + line.delivery_amt_line = delivery_amt * contribution diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index e1f6560c..d0bd515f 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -29,6 +29,7 @@ <field name="so_item_margin"/> <field name="item_percent_margin"/> <field name="so_item_percent_margin"/> + <field name="delivery_amt_line"/> </xpath> <field name="amount_total" position="after"> <field name="total_margin"/> |
