summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-10-04 13:42:30 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-10-04 13:42:30 +0700
commitc4f30a0164ada85a9a4a25cdd03ee7c4e42774a0 (patch)
tree30d246e2cdf3cb1925d88a039926fcd06f2ee82c /indoteknik_custom/models/purchase_order.py
parentd1bc570eae2818bc4b535840f2eb3061b99ca98b (diff)
parent1d6351cbab4df3a5f5ceff92c53560437d7b40a4 (diff)
Merge commit '1d6351cbab4df3a5f5ceff92c53560437d7b40a4'
Diffstat (limited to 'indoteknik_custom/models/purchase_order.py')
-rwxr-xr-xindoteknik_custom/models/purchase_order.py165
1 files changed, 163 insertions, 2 deletions
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index cb048182..54ef60af 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -1,11 +1,31 @@
-from odoo import fields, models, api
+from odoo import fields, models, api, _
+from odoo.exceptions import AccessError, UserError, ValidationError
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)
+ approval_status = fields.Selection([
+ ('pengajuan1', 'Approval Manager'), #siapa? darren - 11
+ ('pengajuan2', 'Approval Pimpinan'), #akbar - 7 temporary not used
+ ('approved', 'Approved'),
+ ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
+ 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")
+ amount_total_without_service = fields.Float('AmtTotalWithoutService', compute='compute_amt_total_without_service')
def get_procurement_status(self):
for purchase_order in self:
@@ -44,3 +64,144 @@ 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 button_confirm(self):
+ res = super(PurchaseOrder, self).button_confirm()
+ 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 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:
+ # 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):
+ 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'
+ # 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()
+ self.approval_status = False
+ return res
+
+ def compute_total_margin(self):
+ 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 -= 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 += line.delivery_amt_line
+ 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
+ # 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()
+
+ 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