diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-09-22 13:46:48 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-09-22 13:46:48 +0700 |
| commit | 60fffef5ee0c91ba58a056823fc2feff6241a303 (patch) | |
| tree | 9135ec67b5f509d74787e8869d4b11b60e39d7fb /indoteknik_custom/models/sale_order.py | |
| parent | b5c15f8ee9171ade6f3d11415a383b0a9f936110 (diff) | |
add calculate margin including delivery fee in purchase order
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 115 |
1 files changed, 67 insertions, 48 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 1db8a445..7366d67a 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -19,6 +19,9 @@ class SaleOrder(models.Model): ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) 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_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount') + def _compute_have_visit_service(self): limit = 20000000 @@ -26,39 +29,56 @@ class SaleOrder(models.Model): if self.amount_total > limit: self.have_visit_service = True - # def sale_order_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 - # # order.approval_status = "pengajuan2" - # # break - # elif line.item_percent_margin <= 40 and (self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7): - # approval1 += 1 - # # order.approval_status = 'pengajuan1' - # # break - # if approval2 > 0: - # order.approval_status = 'pengajuan2' - # elif approval1 > 0: - # order.approval_status = 'pengajuan1' - # else: - # raise UserError("Bisa langsung Confirm") + def sale_order_approve(self): + raise UserError("Bisa langsung Confirm") + # 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 + # # order.approval_status = "pengajuan2" + # # break + # elif line.item_percent_margin <= 40 and (self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7): + # approval1 += 1 + # # order.approval_status = 'pengajuan1' + # # break + # if approval2 > 0: + # order.approval_status = 'pengajuan2' + # elif approval1 > 0: + # order.approval_status = 'pengajuan1' + # else: + # raise UserError("Bisa langsung Confirm") - # def action_cancel(self): - # self.approval_status = False - # return super(SaleOrder, self).action_cancel() + def action_cancel(self): + # self.approval_status = False + return super(SaleOrder, self).action_cancel() def action_confirm(self): - for line in self.order_line: - if line.product_id.id == 232383: - raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) res = super(SaleOrder, self).action_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): + # approval2 += 1 + # elif line.item_percent_margin <= 40 and ( + # self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7): + # approval1 += 1 + # if approval2 > 0: + # raise UserError("Need Tyas / Akbar Approval, atau Approval manual dan lampirkan di Log Internal") + # elif approval1 > 0: + # raise UserError("Need Adela Approval") + # order.approval_status = 'approved' return res def compute_total_margin(self): @@ -75,25 +95,24 @@ class SaleOrder(models.Model): total_percent_margin = round((total_margin / order.amount_untaxed), 4) * 100 order.total_percent_margin = total_percent_margin - # def action_confirm(self): - # res = super(SaleOrder, self).action_confirm() - # 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): - # approval2 += 1 - # elif line.item_percent_margin <= 40 and ( - # self.env.user.id != 8 and self.env.user.id != 6 and self.env.user.id != 7): - # approval1 += 1 - # if approval2 > 0: - # raise UserError("Need Tyas / Akbar Approval, atau Approval manual dan lampirkan di Log Internal") - # elif approval1 > 0: - # raise UserError("Need Adela Approval") - # order.approval_status = 'approved' - # return res + 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 class SaleOrderLine(models.Model): |
