From 60fffef5ee0c91ba58a056823fc2feff6241a303 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 22 Sep 2022 13:46:48 +0700 Subject: add calculate margin including delivery fee in purchase order --- indoteknik_custom/models/purchase_order.py | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') 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 -- cgit v1.2.3 From 54ce5a6396f5d5365d8afba0823167dfb5561cc5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 22 Sep 2022 17:20:57 +0700 Subject: add approval validation in po confirmation --- indoteknik_custom/models/purchase_order.py | 51 ++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index fd02cd2b..b53f973f 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1,4 +1,5 @@ -from odoo import fields, models, api +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError class PurchaseOrder(models.Model): @@ -13,8 +14,8 @@ class PurchaseOrder(models.Model): '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 + ('pengajuan1', 'Approval Manager'), #siapa? darren - 11 + ('pengajuan2', 'Approval Pimpinan'), #akbar - 7 ('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') @@ -92,3 +93,47 @@ class PurchaseOrder(models.Model): if po.amount_untaxed > 0: total_percent_margin = round((total_margin / po.amount_untaxed), 2) * 100 po.total_percent_margin = total_percent_margin + + def button_confirm(self): + res = super(PurchaseOrder, self).button_confirm() + # for line in self.order_line: + # if line.product_id.id == 232383: + # raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) + for order in self: + approval1 = approval2 = 0 + for line in order.order_line: + if not line.product_id: + continue + if (line.item_percent_margin < 15 or line.item_percent_margin == 100) and \ + (self.env.user.id != 6 and self.env.user.id != 7): # tyas or akbar + approval2 += 1 + elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \ + (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): + approval1 += 1 + if approval2 > 0: + raise UserError("Need Tyas / Akbar Approval") + elif approval1 > 0: + raise UserError("Need Adela Approval") + order.approval_status = 'approved' + return res + + def po_approve(self): + for order in self: + if order.state == 'cancel' or order.state == 'done' or order.state == 'sale': + raise UserError("Status harus draft atau sent") + approval1 = approval2 = 0 + for line in order.order_line: + if not line.product_id: + continue + if (line.item_percent_margin < 15 or line.item_percent_margin == 100) and \ + (self.env.user.id != 6 and self.env.user.id != 7): + approval2 += 1 + elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \ + (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): + approval1 += 1 + if approval2 > 0: + order.approval_status = 'pengajuan2' + elif approval1 > 0: + order.approval_status = 'pengajuan1' + else: + raise UserError("Bisa langsung Confirm") -- cgit v1.2.3 From 62dfd611cac52a2099deabf26149b1779926ee7a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 23 Sep 2022 09:31:52 +0700 Subject: override method cancel purchase order and add field approval status in form purchase order --- indoteknik_custom/models/purchase_order.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b53f973f..2c9b72b1 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -108,7 +108,7 @@ class PurchaseOrder(models.Model): (self.env.user.id != 6 and self.env.user.id != 7): # tyas or akbar approval2 += 1 elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \ - (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): + (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): # tyas or akbar or darren approval1 += 1 if approval2 > 0: raise UserError("Need Tyas / Akbar Approval") @@ -137,3 +137,8 @@ class PurchaseOrder(models.Model): order.approval_status = 'pengajuan1' else: raise UserError("Bisa langsung Confirm") + + def button_cancel(self): + res = super(PurchaseOrder, self).button_cancel() + self.approval_status = False + return res -- cgit v1.2.3 From 7ae5b8b7baafb9ed302c3c3e54f3f44664651c06 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 26 Sep 2022 18:25:41 +0700 Subject: Update purchase_order.py, purchase_order_line.py, and 2 more files... --- indoteknik_custom/models/purchase_order.py | 80 ++++++++++++++++-------------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 2c9b72b1..889fc80e 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -96,47 +96,51 @@ class PurchaseOrder(models.Model): def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() - # for line in self.order_line: - # if line.product_id.id == 232383: - # raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) - for order in self: - approval1 = approval2 = 0 - for line in order.order_line: - if not line.product_id: - continue - if (line.item_percent_margin < 15 or line.item_percent_margin == 100) and \ - (self.env.user.id != 6 and self.env.user.id != 7): # tyas or akbar - approval2 += 1 - elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \ - (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): # tyas or akbar or darren - approval1 += 1 - if approval2 > 0: - raise UserError("Need Tyas / Akbar Approval") - elif approval1 > 0: - raise UserError("Need Adela Approval") - order.approval_status = 'approved' + + for line in self.order_line: + sale_order_line = self.env['sale.order.line'].search( + [('product_id', '=', line.product_id.id), + ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') + + est_purchase_price = sale_order_line.purchase_price + real_purchase_price = line.price_unit + real_tax = real_tax_amount = count_real_tax = 0 + for tax in line.taxes_id: + count_real_tax += 1 + real_tax = tax + real_tax_amount += tax.amount + if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ + or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and (self.env.user.id != 6): + raise UserError("Beda tax amount dengan Sales, harus Approval Pak Tyas") + elif est_purchase_price != real_purchase_price and self.env.user.id != 6: + raise UserError("Beda Price dengan Sales, harus Approval Pak Tyas") + self.approval_status = 'approved' + return res def po_approve(self): - for order in self: - if order.state == 'cancel' or order.state == 'done' or order.state == 'sale': - raise UserError("Status harus draft atau sent") - approval1 = approval2 = 0 - for line in order.order_line: - if not line.product_id: - continue - if (line.item_percent_margin < 15 or line.item_percent_margin == 100) and \ - (self.env.user.id != 6 and self.env.user.id != 7): - approval2 += 1 - elif (line.item_percent_margin >= 15 and line.item_percent_margin < 25) and \ - (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 11): - approval1 += 1 - if approval2 > 0: - order.approval_status = 'pengajuan2' - elif approval1 > 0: - order.approval_status = 'pengajuan1' - else: - raise UserError("Bisa langsung Confirm") + approval = 0 + for line in self.order_line: + sale_order_line = self.env['sale.order.line'].search( + [('product_id', '=', line.product_id.id), + ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') + + est_purchase_price = sale_order_line.purchase_price + real_purchase_price = line.price_unit + real_tax = real_tax_amount = count_real_tax = 0 + for tax in line.taxes_id: + count_real_tax += 1 + real_tax = tax + real_tax_amount += tax.amount + if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ + or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and self.env.user.id != 6: + approval += 1 + elif est_purchase_price != real_purchase_price and self.env.user.id != 6: + approval += 1 + if approval > 0: + self.approval_status = "pengajuan1" + else: + raise UserError("Bisa langsung Confirm") def button_cancel(self): res = super(PurchaseOrder, self).button_cancel() -- cgit v1.2.3 From 59354f566bc4d735f5a4a7bd96d663247d1990e2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 27 Sep 2022 09:04:51 +0700 Subject: Update purchase_order.py --- indoteknik_custom/models/purchase_order.py | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 889fc80e..a9d9cc6b 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -7,12 +7,6 @@ class PurchaseOrder(models.Model): sale_order_id = fields.Many2one('sale.order', string='Sale Order') 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? darren - 11 ('pengajuan2', 'Approval Pimpinan'), #akbar - 7 @@ -77,23 +71,6 @@ class PurchaseOrder(models.Model): 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 - def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() @@ -111,9 +88,9 @@ class PurchaseOrder(models.Model): real_tax_amount += tax.amount if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and (self.env.user.id != 6): - raise UserError("Beda tax amount dengan Sales, harus Approval Pak Tyas") + raise UserError("Beda tax amount dengan Sales, harus Approval Manager") elif est_purchase_price != real_purchase_price and self.env.user.id != 6: - raise UserError("Beda Price dengan Sales, harus Approval Pak Tyas") + raise UserError("Beda Price dengan Sales, harus Approval Manager") self.approval_status = 'approved' return res -- cgit v1.2.3 From 90ee21e0c1b2179b53d1dbadd6232bf22a3eea5a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 27 Sep 2022 11:36:23 +0700 Subject: Update purchase_order.py and sale_order.py --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a9d9cc6b..406b17fc 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -9,7 +9,7 @@ class PurchaseOrder(models.Model): procurement_status = fields.Char(string='Procurement Status', compute='get_procurement_status', readonly=True) approval_status = fields.Selection([ ('pengajuan1', 'Approval Manager'), #siapa? darren - 11 - ('pengajuan2', 'Approval Pimpinan'), #akbar - 7 + ('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') -- cgit v1.2.3 From 3a8710d164ced77e532b0b96988d84bb08515602 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 27 Sep 2022 14:42:59 +0700 Subject: Update purchase_order.py, sale_order.py, and sale_order.xml --- indoteknik_custom/models/purchase_order.py | 45 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 406b17fc..cffeff69 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -75,6 +75,10 @@ class PurchaseOrder(models.Model): res = super(PurchaseOrder, self).button_confirm() for line in self.order_line: + if not line.product_id: + continue + if line.product_id.type == 'service' and self.env.user.id != 6: + raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager") sale_order_line = self.env['sale.order.line'].search( [('product_id', '=', line.product_id.id), ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') @@ -89,8 +93,10 @@ class PurchaseOrder(models.Model): if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and (self.env.user.id != 6): raise UserError("Beda tax amount dengan Sales, harus Approval Manager") - elif est_purchase_price != real_purchase_price and self.env.user.id != 6: + elif est_purchase_price < real_purchase_price and self.env.user.id != 6: raise UserError("Beda Price dengan Sales, harus Approval Manager") + # elif line.product_id.type == 'service' and self.env.user_id != 6: + # raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager") self.approval_status = 'approved' return res @@ -98,22 +104,29 @@ class PurchaseOrder(models.Model): def po_approve(self): approval = 0 for line in self.order_line: - sale_order_line = self.env['sale.order.line'].search( - [('product_id', '=', line.product_id.id), - ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') - - est_purchase_price = sale_order_line.purchase_price - real_purchase_price = line.price_unit - real_tax = real_tax_amount = count_real_tax = 0 - for tax in line.taxes_id: - count_real_tax += 1 - real_tax = tax - real_tax_amount += tax.amount - if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ - or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and self.env.user.id != 6: - approval += 1 - elif est_purchase_price != real_purchase_price and self.env.user.id != 6: + if not line.product_id: + continue + elif line.product_id.type == 'service' and self.env.user.id != 6: approval += 1 + else: + sale_order_line = self.env['sale.order.line'].search( + [('product_id', '=', line.product_id.id), + ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') + + est_purchase_price = sale_order_line.purchase_price + real_purchase_price = line.price_unit + real_tax = real_tax_amount = count_real_tax = 0 + for tax in line.taxes_id: + count_real_tax += 1 + real_tax = tax + real_tax_amount += tax.amount + if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ + or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and self.env.user.id != 6: + approval += 1 + elif est_purchase_price != real_purchase_price and self.env.user.id != 6: + approval += 1 + elif line.product_id.type == 'service' and self.env.user.id != 6: + approval += 1 if approval > 0: self.approval_status = "pengajuan1" else: -- cgit v1.2.3 From 7e27706cca01443b8476afeaa856fa2cc3c12deb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 28 Sep 2022 11:14:28 +0700 Subject: change approval sales to vita and po to akbar and tyas --- indoteknik_custom/models/purchase_order.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index cffeff69..ca106a68 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -91,9 +91,10 @@ class PurchaseOrder(models.Model): real_tax = tax real_tax_amount += tax.amount if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ - or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and (self.env.user.id != 6): + or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) \ + and (self.env.user.id != 6 and self.env.user.id != 7): raise UserError("Beda tax amount dengan Sales, harus Approval Manager") - elif est_purchase_price < real_purchase_price and self.env.user.id != 6: + elif est_purchase_price < real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: raise UserError("Beda Price dengan Sales, harus Approval Manager") # elif line.product_id.type == 'service' and self.env.user_id != 6: # raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager") @@ -121,11 +122,12 @@ class PurchaseOrder(models.Model): real_tax = tax real_tax_amount += tax.amount if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ - or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) and self.env.user.id != 6: + or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) \ + and (self.env.user.id != 6 and self.env.user.id != 7): approval += 1 - elif est_purchase_price != real_purchase_price and self.env.user.id != 6: + elif est_purchase_price != real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: approval += 1 - elif line.product_id.type == 'service' and self.env.user.id != 6: + elif line.product_id.type == 'service' and self.env.user.id != 6 and self.env.user.id != 7: approval += 1 if approval > 0: self.approval_status = "pengajuan1" -- cgit v1.2.3 From 009be5919cb5835f98f5882f69b3a7652e8ec658 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 28 Sep 2022 11:17:02 +0700 Subject: Update purchase_order.py --- indoteknik_custom/models/purchase_order.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index ca106a68..acc737e8 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -96,8 +96,6 @@ class PurchaseOrder(models.Model): raise UserError("Beda tax amount dengan Sales, harus Approval Manager") elif est_purchase_price < real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: raise UserError("Beda Price dengan Sales, harus Approval Manager") - # elif line.product_id.type == 'service' and self.env.user_id != 6: - # raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager") self.approval_status = 'approved' return res -- cgit v1.2.3 From 597d6458234a14bd20e7fba8a0ceb07168423d2a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 28 Sep 2022 16:25:01 +0700 Subject: Update purchase_order.py, purchase_order_line.py, and 3 more files... --- indoteknik_custom/models/purchase_order.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index acc737e8..60121919 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -14,6 +14,18 @@ class PurchaseOrder(models.Model): ], 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', + help="Total Margin in Sales Order Header") + total_percent_margin = fields.Float( + 'Margin%', compute='compute_total_margin', + help="Total % Margin in Sales Order Header") + total_so_margin = fields.Float( + 'SO Margin', compute='compute_total_margin', + help="Total Margin in Sales Order Header") + total_so_percent_margin = fields.Float( + 'SO Margin%', compute='compute_total_margin', + help="Total % Margin in Sales Order Header") def get_procurement_status(self): for purchase_order in self: @@ -136,3 +148,13 @@ class PurchaseOrder(models.Model): res = super(PurchaseOrder, self).button_cancel() self.approval_status = False return res + + def compute_total_margin(self): + if not self.order_line: + self.total_margin = 0 + self.total_percent_margin = 0 + self.total_so_margin = 0 + self.total_so_percent_margin = 0 + return + for line in self.order_line: + line.compute_item_margin() -- cgit v1.2.3 From ac37a854362dbaaf8a88431ea5ab077a37f3c5f9 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 28 Sep 2022 17:17:44 +0700 Subject: Update purchase_order.py and purchase_order_line.py --- indoteknik_custom/models/purchase_order.py | 119 ++++++++++++++++------------- 1 file changed, 65 insertions(+), 54 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 60121919..2966eeed 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -85,64 +85,75 @@ class PurchaseOrder(models.Model): def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() - - for line in self.order_line: - if not line.product_id: - continue - if line.product_id.type == 'service' and self.env.user.id != 6: - raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager") - sale_order_line = self.env['sale.order.line'].search( - [('product_id', '=', line.product_id.id), - ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') - - est_purchase_price = sale_order_line.purchase_price - real_purchase_price = line.price_unit - real_tax = real_tax_amount = count_real_tax = 0 - for tax in line.taxes_id: - count_real_tax += 1 - real_tax = tax - real_tax_amount += tax.amount - if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ - or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) \ - and (self.env.user.id != 6 and self.env.user.id != 7): - raise UserError("Beda tax amount dengan Sales, harus Approval Manager") - elif est_purchase_price < real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: - raise UserError("Beda Price dengan Sales, harus Approval Manager") - self.approval_status = 'approved' + test = self.env.user.id + if self.total_percent_margin < self.total_so_percent_margin and self.env.user.id != 6: + raise UserError("Beda Margin dengan Sales, harus approval Manager") + if not self.sale_order_id: + if self.env.user.id != 6 and self.env.user.id != 7: + raise UserError("Tidak ada link dengan SO, harus approval Manager") + self.approval_status = 'approved' + + # for line in self.order_line: + # if not line.product_id: + # continue + # if line.product_id.type == 'service' and self.env.user.id != 6: + # raise UserError("Ada tambahan Ongkos kirim, harus Approval Manager") + # sale_order_line = self.env['sale.order.line'].search( + # [('product_id', '=', line.product_id.id), + # ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') + # + # est_purchase_price = sale_order_line.purchase_price + # real_purchase_price = line.price_unit + # real_tax = real_tax_amount = count_real_tax = 0 + # for tax in line.taxes_id: + # count_real_tax += 1 + # real_tax = tax + # real_tax_amount += tax.amount + # if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ + # or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) \ + # and (self.env.user.id != 6 and self.env.user.id != 7): + # raise UserError("Beda tax amount dengan Sales, harus Approval Manager") + # elif est_purchase_price < real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: + # raise UserError("Beda Price dengan Sales, harus Approval Manager") + # self.approval_status = 'approved' return res def po_approve(self): - approval = 0 - for line in self.order_line: - if not line.product_id: - continue - elif line.product_id.type == 'service' and self.env.user.id != 6: - approval += 1 - else: - sale_order_line = self.env['sale.order.line'].search( - [('product_id', '=', line.product_id.id), - ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') - - est_purchase_price = sale_order_line.purchase_price - real_purchase_price = line.price_unit - real_tax = real_tax_amount = count_real_tax = 0 - for tax in line.taxes_id: - count_real_tax += 1 - real_tax = tax - real_tax_amount += tax.amount - if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ - or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) \ - and (self.env.user.id != 6 and self.env.user.id != 7): - approval += 1 - elif est_purchase_price != real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: - approval += 1 - elif line.product_id.type == 'service' and self.env.user.id != 6 and self.env.user.id != 7: - approval += 1 - if approval > 0: - self.approval_status = "pengajuan1" - else: + if (self.total_percent_margin == self.total_so_percent_margin) and (self.env.user.id == 6 or self.env.user.id == 7): raise UserError("Bisa langsung Confirm") + else: + self.approval_status = 'pengajuan1' + # approval = 0 + # for line in self.order_line: + # if not line.product_id: + # continue + # elif line.product_id.type == 'service' and self.env.user.id != 6: + # approval += 1 + # else: + # sale_order_line = self.env['sale.order.line'].search( + # [('product_id', '=', line.product_id.id), + # ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') + # + # est_purchase_price = sale_order_line.purchase_price + # real_purchase_price = line.price_unit + # real_tax = real_tax_amount = count_real_tax = 0 + # for tax in line.taxes_id: + # count_real_tax += 1 + # real_tax = tax + # real_tax_amount += tax.amount + # if (sale_order_line.purchase_tax_id.amount != real_tax_amount or count_real_tax > 1 \ + # or real_tax.price_include != sale_order_line.purchase_tax_id.price_include) \ + # and (self.env.user.id != 6 and self.env.user.id != 7): + # approval += 1 + # elif est_purchase_price != real_purchase_price and self.env.user.id != 6 and self.env.user.id != 7: + # approval += 1 + # elif line.product_id.type == 'service' and self.env.user.id != 6 and self.env.user.id != 7: + # approval += 1 + # if approval > 0: + # self.approval_status = "pengajuan1" + # else: + # raise UserError("Bisa langsung Confirm") def button_cancel(self): res = super(PurchaseOrder, self).button_cancel() @@ -150,7 +161,7 @@ class PurchaseOrder(models.Model): return res def compute_total_margin(self): - if not self.order_line: + if not self.order_line or not self.sale_order_id: self.total_margin = 0 self.total_percent_margin = 0 self.total_so_margin = 0 -- cgit v1.2.3 From 43a8e9a7f2d6ba127de9bcd40925b838b1f5eaeb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 08:54:16 +0700 Subject: Update __manifest__.py, __init__.py, and 3 more files... --- indoteknik_custom/models/purchase_order.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 2966eeed..a3226083 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -85,12 +85,12 @@ class PurchaseOrder(models.Model): def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() - test = self.env.user.id - if self.total_percent_margin < self.total_so_percent_margin and self.env.user.id != 6: + test = self.env.user.is_leader + test2 = self.env.user.is_purchasing_manager + if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Beda Margin dengan Sales, harus approval Manager") - if not self.sale_order_id: - if self.env.user.id != 6 and self.env.user.id != 7: - raise UserError("Tidak ada link dengan SO, harus approval Manager") + if not self.sale_order_id and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: + raise UserError("Tidak ada link dengan SO, harus approval Manager") self.approval_status = 'approved' # for line in self.order_line: @@ -120,7 +120,9 @@ class PurchaseOrder(models.Model): return res def po_approve(self): - if (self.total_percent_margin == self.total_so_percent_margin) and (self.env.user.id == 6 or self.env.user.id == 7): + if self.env.user.is_leader or self.env.user.is_purchasing_manager: + raise UserError("Bisa langsung Confirm") + elif self.total_percent_margin == self.total_so_percent_margin and self.sale_order_id: raise UserError("Bisa langsung Confirm") else: self.approval_status = 'pengajuan1' -- cgit v1.2.3 From 7f1d89998467de2b2519bc17dffb5f9c2723c230 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 09:38:13 +0700 Subject: Update purchase_order.py and purchase_order_line.py --- indoteknik_custom/models/purchase_order.py | 35 ++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a3226083..ff07d32c 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -163,11 +163,38 @@ class PurchaseOrder(models.Model): return res def compute_total_margin(self): - if not self.order_line or not self.sale_order_id: + sum_so_margin = sum_sales_price = sum_margin = 0 + for line in self.order_line: + sale_order_line = self.env['sale.order.line'].search( + [('product_id', '=', line.product_id.id), + ('order_id', '=', line.order_id.sale_order_id.id)], limit=1, order='price_reduce_taxexcl') + 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) + 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) + real_item_margin = sales_price - purchase_price + sum_margin += real_item_margin + + if sum_so_margin > 0 and sum_sales_price > 0 and sum_margin > 0: + self.total_so_margin = sum_so_margin + self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 + self.total_margin = sum_margin + self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 + else: self.total_margin = 0 self.total_percent_margin = 0 self.total_so_margin = 0 self.total_so_percent_margin = 0 - return - for line in self.order_line: - line.compute_item_margin() + # if not self.order_line or not self.sale_order_id: + # self.total_margin = 0 + # self.total_percent_margin = 0 + # self.total_so_margin = 0 + # self.total_so_percent_margin = 0 + # return + # for line in self.order_line: + # line.compute_item_margin() -- cgit v1.2.3 From c8295772706a8e27d4633706b357ade5c4a8bba8 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 10:58:52 +0700 Subject: Update purchase_order.py and sale_order.py --- indoteknik_custom/models/purchase_order.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index ff07d32c..6b038e69 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -171,8 +171,7 @@ 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 -= round((sale_order_line.order_id.delivery_amt / sale_order_line.order_id.count_line_product), 2) sum_sales_price += sales_price purchase_price = line.price_subtotal if line.order_id.delivery_amount > 0: -- cgit v1.2.3 From c76003a8551021113c05ac35b9bc86fb598a0a87 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 11:37:43 +0700 Subject: Update purchase_order.py and sale_order.py --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 6b038e69..d51115f8 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -179,7 +179,7 @@ class PurchaseOrder(models.Model): real_item_margin = sales_price - purchase_price sum_margin += real_item_margin - if sum_so_margin > 0 and sum_sales_price > 0 and sum_margin > 0: + if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: self.total_so_margin = sum_so_margin self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 self.total_margin = sum_margin -- cgit v1.2.3 From 1e40f3b647d6825779503858bb2ed2d0f8a4b184 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 19:06:49 +0700 Subject: Update purchase_order.py, purchase_order_line.py, and 2 more files... --- indoteknik_custom/models/purchase_order.py | 34 ++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') 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 -- cgit v1.2.3