diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-09-28 17:17:44 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-09-28 17:17:44 +0700 |
| commit | ac37a854362dbaaf8a88431ea5ab077a37f3c5f9 (patch) | |
| tree | 9e2774cd88cc935bf6d7a87c2a73011090660f0e | |
| parent | 597d6458234a14bd20e7fba8a0ceb07168423d2a (diff) | |
Update purchase_order.py and purchase_order_line.py
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 119 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 2 |
2 files changed, 66 insertions, 55 deletions
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 diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index fcfab1da..4965b507 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -42,7 +42,7 @@ class PurchaseOrderLine(models.Model): def compute_item_margin(self): sum_so_margin = sum_sales_price = sum_margin = 0 for line in self: - if not line.product_id or line.product_id.type == 'service': + if not line.product_id or line.product_id.type == 'service' or not self.order_id.sale_order_id: line.so_item_margin = 0 line.so_item_percent_margin = 0 line.item_margin = 0 |
