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 ++++++++++- indoteknik_custom/models/purchase_order_line.py | 32 +++++++ indoteknik_custom/models/sale_order.py | 115 ++++++++++++++---------- indoteknik_custom/views/purchase_order.xml | 8 ++ indoteknik_custom/views/sale_order.xml | 6 ++ 5 files changed, 162 insertions(+), 49 deletions(-) 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 diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index b4be9ffc..24afcab6 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -4,6 +4,15 @@ from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' + sales_price = fields.Float( + 'Sales Price', compute='compute_item_margin', + help="Sales Price in Purchase Order Line") + item_margin = fields.Float( + 'Total Margin', compute='compute_item_margin', + help="Total Margin in Purchase Order Line") + item_percent_margin = fields.Float( + 'Total Percent Margin', compute='compute_item_margin', + help="Total % Margin in Purchase Order Line") # Override method from addons/purchase/models/purchase.py @api.onchange('product_qty', 'product_uom') @@ -25,3 +34,26 @@ class PurchaseOrderLine(models.Model): self.price_unit = price_unit return res + + def compute_item_margin(self): + for line in self: + if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service': + line.item_margin = 0 + line.item_percent_margin = 0 + continue + 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') + + # untaxed sales price + sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty + # must add expedition price in sales_price, expedition payed by customer? + # sales_price -= round((line.order_id.sale_order_id.delivery_amount / line.order_id.sale_order_id.count_line_product), 2) + # untaxed purchase price + purchase_price = line.price_subtotal + # must add expedition price in purchase_price as expenses + purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) + margin_per_item = sales_price - purchase_price + line.item_margin = margin_per_item + if sales_price > 0: + line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 \ No newline at end of file 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): diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index f209d18a..7df2ca9f 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -17,6 +17,14 @@ + + + + + + + + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 19182a6b..b2466b0d 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -6,6 +6,12 @@ sale.order + -- 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 ++++++++++++++++++++++++++++-- indoteknik_custom/views/purchase_order.xml | 6 ++++ 2 files changed, 54 insertions(+), 3 deletions(-) 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") diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 7df2ca9f..21ce3c58 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -14,6 +14,12 @@ attrs="{'invisible': ['|', ('sale_order_id', '=', False), ('state', 'not in', ['draft'])]}" /> + -- cgit v1.2.3 From f9d6b340a6e75799edc3a6a2a9e5bd6086fc8a3f Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 23 Sep 2022 09:14:46 +0700 Subject: add volumn approval status and procurement status in rfq and purchase order --- indoteknik_custom/views/purchase_order.xml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 21ce3c58..a1e6f08c 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -34,4 +34,28 @@ + + + Purchase + purchase.order + + + + + + + + + + + Purchase + purchase.order + + + + + + + + \ No newline at end of file -- 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 ++++++- indoteknik_custom/views/purchase_order.xml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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 diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index a1e6f08c..ccedd857 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -22,6 +22,7 @@ + -- cgit v1.2.3 From f38c1291c45beebd9c44939aee1adbf46cdbd7dd Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 24 Sep 2022 10:19:24 +0700 Subject: skip calculate margin if not have sale order --- indoteknik_custom/models/purchase_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 24afcab6..55381c6d 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -37,7 +37,7 @@ class PurchaseOrderLine(models.Model): def compute_item_margin(self): for line in self: - if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service': + if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service' or not line.order_id.sale_order_id.id: line.item_margin = 0 line.item_percent_margin = 0 continue -- cgit v1.2.3 From 248fd7cb0c93e60bdfccaf095cdb601a3319b65e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 24 Sep 2022 11:11:49 +0700 Subject: add several column in sales order and order line --- indoteknik_custom/models/sale_order.py | 20 ++++++++++++++++++-- indoteknik_custom/views/sale_order.xml | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7366d67a..30ac2058 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -21,6 +21,9 @@ class SaleOrder(models.Model): 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') + shipping_cost_covered = fields.Boolean('Shipping Cost Covered', help='Centang jika Shipping Cost ditanggung oleh ' + 'Indoteknik, jika dicentang akan ' + 'mempengaruhi margin') def _compute_have_visit_service(self): @@ -118,11 +121,24 @@ class SaleOrder(models.Model): class SaleOrderLine(models.Model): _inherit = 'sale.order.line' item_margin = fields.Float( - 'Total Margin', compute='compute_item_margin', + 'Margin', compute='compute_item_margin', help="Total Margin in Sales Order Header") item_percent_margin = fields.Float( - 'Total Percent Margin', compute='compute_item_margin', + '%Margin', compute='compute_item_margin', help="Total % Margin in Sales Order Header") + vendor = fields.Many2one( + 'res.partner', string='Vendor', readonly=True, + states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, + required=True, change_default=True, index=True, tracking=1, + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",) + vendor = fields.Many2one( + 'res.partner', string='Vendor', readonly=True, + states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, + change_default=True, index=True, tracking=1, + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", ) + purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0) + tax_id = fields.Many2one('account.tax', string='Tax', + domain=['|', ('active', '=', False), ('active', '=', True)]) def compute_item_margin(self): for line in self: diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index b2466b0d..c101fe1b 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -13,9 +13,15 @@ /> + + + + + + -- cgit v1.2.3 From 01b658ddbb6ed4e5c493da2c9cae92ce80a7e135 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 24 Sep 2022 11:39:41 +0700 Subject: fix error column sale order --- indoteknik_custom/models/sale_order.py | 2 +- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 30ac2058..08e7281e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -137,7 +137,7 @@ class SaleOrderLine(models.Model): change_default=True, index=True, tracking=1, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", ) purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0) - tax_id = fields.Many2one('account.tax', string='Tax', + purchase_tax_id = fields.Many2one('account.tax', string='Tax', domain=['|', ('active', '=', False), ('active', '=', True)]) def compute_item_margin(self): diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index c101fe1b..03a6b45c 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -21,7 +21,7 @@ - + -- cgit v1.2.3 From 18a08e93126100d572a56e4deced21434082bd72 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 26 Sep 2022 13:29:17 +0700 Subject: Update sale_order.py and sale_order.xml - calculate margin with input purchase price --- indoteknik_custom/models/sale_order.py | 36 ++++++++++++++++++---------------- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 08e7281e..4d1550aa 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -95,7 +95,7 @@ class SaleOrder(models.Model): total_margin += line.item_margin order.total_margin = total_margin if order.amount_untaxed > 0: - total_percent_margin = round((total_margin / order.amount_untaxed), 4) * 100 + total_percent_margin = round((total_margin / order.amount_untaxed), 2) * 100 order.total_percent_margin = total_percent_margin def compute_count_line_product(self): @@ -126,12 +126,7 @@ class SaleOrderLine(models.Model): item_percent_margin = fields.Float( '%Margin', compute='compute_item_margin', help="Total % Margin in Sales Order Header") - vendor = fields.Many2one( - 'res.partner', string='Vendor', readonly=True, - states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, - required=True, change_default=True, index=True, tracking=1, - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",) - vendor = fields.Many2one( + vendor_id = fields.Many2one( 'res.partner', string='Vendor', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, change_default=True, index=True, tracking=1, @@ -142,17 +137,24 @@ class SaleOrderLine(models.Model): def compute_item_margin(self): for line in self: - if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0: + if not line.product_id or line.product_id.type == 'service' \ + or line.price_unit <= 0 or line.product_uom_qty <= 0 \ + or not line.vendor_id or not line.purchase_tax_id: line.item_margin = 0 line.item_percent_margin = 0 continue - subtotal_untaxed = line.price_subtotal - purchase_pricelist = self.env['purchase.pricelist'].search( - [('product_id', '=', line.product_id.id)], limit=1, order='product_price') - purchase_pricelist_untaxed = 0 - if purchase_pricelist.product_price > 0: - purchase_pricelist_untaxed = purchase_pricelist.product_price / 1.11 - margin_per_item = subtotal_untaxed - (purchase_pricelist_untaxed * line.product_uom_qty) + # calculate margin without tax + sales_price = line.price_reduce_taxexcl * line.product_uom_qty + # minus with delivery if covered by indoteknik + if line.order_id.shipping_cost_covered: + sales_price -= round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) + + purchase_price = line.purchase_price + if line.purchase_tax_id.price_include: + purchase_price = line.purchase_price / 1.11 + + purchase_price = purchase_price * line.product_uom_qty + margin_per_item = sales_price - purchase_price line.item_margin = margin_per_item - if subtotal_untaxed > 0: - line.item_percent_margin = round((margin_per_item / subtotal_untaxed), 4) * 100 + # if sales_price > 0: + line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 03a6b45c..0e2d2923 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -19,7 +19,7 @@ - + -- cgit v1.2.3 From 300b62f3ca9898d31254c53dda267a6cc8feaaef Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 26 Sep 2022 14:17:54 +0700 Subject: Update sale_order.py - add approval process for sales order TODO change approval to Sales Manager --- indoteknik_custom/models/sale_order.py | 84 ++++++++++++++++------------------ 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 4d1550aa..c643aa6d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -13,8 +13,8 @@ class SaleOrder(models.Model): 'Total Percent Margin', compute='compute_total_margin', help="Total % Margin in Sales Order Header") approval_status = fields.Selection([ - ('pengajuan1', 'Approval Adela'), - ('pengajuan2', 'Approval Tyas'), + ('pengajuan1', 'Approval Manager'), + ('pengajuan2', 'Approval Pimpinan'), ('approved', 'Approved'), ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method') @@ -33,55 +33,49 @@ class SaleOrder(models.Model): self.have_visit_service = True 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") + # 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 or line.product_id.type == 'service': + continue + if (line.item_percent_margin <= 15) and (self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas + approval2 += 1 + elif line.item_percent_margin <= 25 and (self.env.user.id != 19 and self.env.user.id != 6 and self.env.user.id != 7): + approval1 += 1 + 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 + self.approval_status = False return super(SaleOrder, self).action_cancel() def action_confirm(self): 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' + 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 or line.product_id.type == 'service': + continue + if (line.item_percent_margin <= 15) and (self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas will approve + approval2 += 1 + elif line.item_percent_margin <= 25 and (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 19): # darren? + approval1 += 1 + if approval2 > 0: + raise UserError("Harus diapprove oleh Pimpinan (Akbar / Tyas)") + elif approval1 > 0: + raise UserError("Harus diapprove oleh Manager (?)") + order.approval_status = 'approved' return res def compute_total_margin(self): -- cgit v1.2.3 From 0b48304775255b09de9c2aeba55cd958a860954c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 26 Sep 2022 14:18:59 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index c643aa6d..ad50712f 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -18,14 +18,14 @@ class SaleOrder(models.Model): ('approved', 'Approved'), ], 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') + 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') shipping_cost_covered = fields.Boolean('Shipping Cost Covered', help='Centang jika Shipping Cost ditanggung oleh ' 'Indoteknik, jika dicentang akan ' 'mempengaruhi margin') - def _compute_have_visit_service(self): limit = 20000000 self.have_visit_service = False @@ -41,9 +41,11 @@ class SaleOrder(models.Model): for line in order.order_line: if not line.product_id or line.product_id.type == 'service': continue - if (line.item_percent_margin <= 15) and (self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas + if (line.item_percent_margin <= 15) and ( + self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas approval2 += 1 - elif line.item_percent_margin <= 25 and (self.env.user.id != 19 and self.env.user.id != 6 and self.env.user.id != 7): + elif line.item_percent_margin <= 25 and ( + self.env.user.id != 19 and self.env.user.id != 6 and self.env.user.id != 7): approval1 += 1 if approval2 > 0: order.approval_status = 'pengajuan2' @@ -67,9 +69,11 @@ class SaleOrder(models.Model): for line in order.order_line: if not line.product_id or line.product_id.type == 'service': continue - if (line.item_percent_margin <= 15) and (self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas will approve + if (line.item_percent_margin <= 15) and ( + self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas will approve approval2 += 1 - elif line.item_percent_margin <= 25 and (self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 19): # darren? + elif line.item_percent_margin <= 25 and ( + self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 19): # darren? approval1 += 1 if approval2 > 0: raise UserError("Harus diapprove oleh Pimpinan (Akbar / Tyas)") @@ -127,7 +131,7 @@ class SaleOrderLine(models.Model): domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", ) 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)]) + domain=['|', ('active', '=', False), ('active', '=', True)]) def compute_item_margin(self): for line in self: -- cgit v1.2.3 From 98d8bb612184f5354c076f52143afcfad4e05e6f Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 26 Sep 2022 14:37:00 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index ad50712f..e317fb8e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -156,3 +156,13 @@ class SaleOrderLine(models.Model): line.item_margin = margin_per_item # if sales_price > 0: line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 + + @api.onchange('vendor_id') + def onchange_vendor_id(self): + if not self.product_id or self.product_id.type == 'service': + return + test1 = self.vendor_id.id + test2 = self.product_id.id + purchase_price = self.env['purchase.pricelist'].search( + [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) + self.purchase_price = purchase_price.product_price -- 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 +++++++++++++------------ indoteknik_custom/models/purchase_order_line.py | 68 +++++++++++---------- indoteknik_custom/models/sale_order.py | 2 - indoteknik_custom/views/purchase_order.xml | 8 --- 4 files changed, 78 insertions(+), 80 deletions(-) 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() diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 55381c6d..4229fcea 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -1,18 +1,10 @@ -from odoo import fields, models, api +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' - sales_price = fields.Float( - 'Sales Price', compute='compute_item_margin', - help="Sales Price in Purchase Order Line") - item_margin = fields.Float( - 'Total Margin', compute='compute_item_margin', - help="Total Margin in Purchase Order Line") - item_percent_margin = fields.Float( - 'Total Percent Margin', compute='compute_item_margin', - help="Total % Margin in Purchase Order Line") # Override method from addons/purchase/models/purchase.py @api.onchange('product_qty', 'product_uom') @@ -35,25 +27,37 @@ class PurchaseOrderLine(models.Model): self.price_unit = price_unit return res - def compute_item_margin(self): - for line in self: - if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service' or not line.order_id.sale_order_id.id: - line.item_margin = 0 - line.item_percent_margin = 0 - continue - 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') - - # untaxed sales price - sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty - # must add expedition price in sales_price, expedition payed by customer? - # sales_price -= round((line.order_id.sale_order_id.delivery_amount / line.order_id.sale_order_id.count_line_product), 2) - # untaxed purchase price - purchase_price = line.price_subtotal - # must add expedition price in purchase_price as expenses - purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) - margin_per_item = sales_price - purchase_price - line.item_margin = margin_per_item - if sales_price > 0: - line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 \ No newline at end of file + # def compute_item_margin(self): + # for line in self: + # if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service' or not line.order_id.sale_order_id.id: + # line.item_margin = 0 + # line.item_percent_margin = 0 + # continue + # 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 = 0 + # real_tax_amount = 0 + # 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: + # raise UserError("Beda tax amount dengan Sales") + # + # # untaxed sales price + # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty + # # must add expedition price in sales_price, expedition payed by customer? + # # sales_price -= round((line.order_id.sale_order_id.delivery_amount / line.order_id.sale_order_id.count_line_product), 2) + # # untaxed purchase price + # purchase_price = line.price_subtotal + # # must add expedition price in purchase_price as expenses + # purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) + # margin_per_item = sales_price - purchase_price + # line.item_margin = margin_per_item + # if sales_price > 0: + # line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 \ No newline at end of file diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e317fb8e..1fb88495 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -161,8 +161,6 @@ class SaleOrderLine(models.Model): def onchange_vendor_id(self): if not self.product_id or self.product_id.type == 'service': return - test1 = self.vendor_id.id - test2 = self.product_id.id purchase_price = self.env['purchase.pricelist'].search( [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) self.purchase_price = purchase_price.product_price diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index ccedd857..37b9c0cb 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -24,14 +24,6 @@ - - - - - - - - -- 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(-) 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 +- indoteknik_custom/models/sale_order.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 1fb88495..73047171 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -39,6 +39,8 @@ class SaleOrder(models.Model): raise UserError("Status harus draft atau sent") approval1 = approval2 = 0 for line in order.order_line: + if line.product_id.id == 232383: + raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.product_id or line.product_id.type == 'service': continue if (line.item_percent_margin <= 15) and ( -- 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 +++++++++++++++++++----------- indoteknik_custom/models/sale_order.py | 32 +++++++++++++-------- indoteknik_custom/views/sale_order.xml | 2 ++ 3 files changed, 51 insertions(+), 28 deletions(-) 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: diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 73047171..70e2d63e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -21,10 +21,15 @@ class SaleOrder(models.Model): 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') + # delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount') + delivery_amt = fields.Float('Delivery Amt') shipping_cost_covered = fields.Boolean('Shipping Cost Covered', help='Centang jika Shipping Cost ditanggung oleh ' - 'Indoteknik, jika dicentang akan ' + 'Indoteknik (Finance), jika dicentang akan ' 'mempengaruhi margin') + shipping_paid_by = fields.Selection([ + ('indoteknik', 'Indoteknik'), + ('customer', 'Customer') + ], string='Shipping Paid by', help='Siapa yang talangin Biaya kirim?',copy=False) def _compute_have_visit_service(self): limit = 20000000 @@ -39,10 +44,12 @@ class SaleOrder(models.Model): raise UserError("Status harus draft atau sent") approval1 = approval2 = 0 for line in order.order_line: - if line.product_id.id == 232383: - raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.product_id or line.product_id.type == 'service': continue + if line.product_id.id == 232383: + raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) + if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: + raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) if (line.item_percent_margin <= 15) and ( self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas approval2 += 1 @@ -109,13 +116,14 @@ class SaleOrder(models.Model): 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_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 + # order.delivery_amt = amount class SaleOrderLine(models.Model): @@ -147,7 +155,7 @@ 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: - sales_price -= round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) + 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: diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 0e2d2923..2260ddc1 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -14,6 +14,8 @@ + + -- cgit v1.2.3 From d023b4f2564c7d2fbe3d61a2348250569f182dc4 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 28 Sep 2022 10:59:19 +0700 Subject: Update sale_order.py and sale_order.xml --- indoteknik_custom/models/sale_order.py | 36 +++++++++++++++++++++------------- indoteknik_custom/views/sale_order.xml | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 70e2d63e..1cd358ab 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -21,15 +21,17 @@ class SaleOrder(models.Model): 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') delivery_amt = fields.Float('Delivery Amt') - shipping_cost_covered = fields.Boolean('Shipping Cost Covered', help='Centang jika Shipping Cost ditanggung oleh ' - 'Indoteknik (Finance), jika dicentang akan ' - 'mempengaruhi margin') + shipping_cost_covered = fields.Selection([ + ('indoteknik', 'Indoteknik'), + ('customer', 'Customer') + ], string='Shipping Paid by', help='Siapa yang menanggung biaya ekspedisi?', copy=False) shipping_paid_by = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') - ], string='Shipping Paid by', help='Siapa yang talangin Biaya kirim?',copy=False) + ], string='Shipping Paid by', help='Siapa yang talangin dulu Biaya ekspedisi-nya?', copy=False) + sales_tax_id = fields.Many2one('account.tax', string='Tax', + domain=['|', ('active', '=', False), ('active', '=', True)]) def _compute_have_visit_service(self): limit = 20000000 @@ -116,14 +118,11 @@ class SaleOrder(models.Model): 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 - # order.delivery_amt = amount + @api.onchange('sales_tax_id') + def onchange_sales_tax_id(self): + for line in self.order_line: + # line.tax_id = self.sales_tax_id + line.product_id_change() class SaleOrderLine(models.Model): @@ -154,7 +153,7 @@ class SaleOrderLine(models.Model): # calculate margin without tax sales_price = line.price_reduce_taxexcl * line.product_uom_qty # minus with delivery if covered by indoteknik - if line.order_id.shipping_cost_covered: + if line.order_id.shipping_cost_covered == 'indoteknik': sales_price -= round((line.order_id.delivery_amt / line.order_id.count_line_product), 2) purchase_price = line.purchase_price @@ -174,3 +173,12 @@ class SaleOrderLine(models.Model): purchase_price = self.env['purchase.pricelist'].search( [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) self.purchase_price = purchase_price.product_price + self.purchase_tax_id = 22 + + @api.onchange('product_id') + def product_id_change(self): + for line in self: + super(SaleOrderLine, self).product_id_change() + if line.product_id: + line.tax_id = line.order_id.sales_tax_id + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 2260ddc1..17902aca 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -16,6 +16,7 @@ + @@ -24,7 +25,6 @@ - -- 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 +++++++----- indoteknik_custom/models/sale_order.py | 14 +++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) 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" diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 1cd358ab..d1200de2 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -44,6 +44,8 @@ class SaleOrder(models.Model): for order in self: if order.state == 'cancel' or order.state == 'done' or order.state == 'sale': raise UserError("Status harus draft atau sent") + if not order.sales_tax_id: + raise UserError("Tax di Header harus diisi") approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': @@ -71,20 +73,22 @@ class SaleOrder(models.Model): def action_confirm(self): 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: + if not order.sales_tax_id: + raise UserError("Tax di Header harus diisi") approval1 = approval2 = 0 for line in order.order_line: + if line.product_id.id == 232383: + raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) + if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: + raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) if not line.product_id or line.product_id.type == 'service': continue if (line.item_percent_margin <= 15) and ( self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas will approve approval2 += 1 elif line.item_percent_margin <= 25 and ( - self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 19): # darren? + self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 377): # vita approval1 += 1 if approval2 > 0: raise UserError("Harus diapprove oleh Pimpinan (Akbar / Tyas)") -- 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(-) 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 +++++++ indoteknik_custom/models/purchase_order_line.py | 86 +++++++++++++++---------- indoteknik_custom/models/sale_order.py | 9 ++- indoteknik_custom/views/purchase_order.xml | 12 ++++ indoteknik_custom/views/sale_order.xml | 2 +- 5 files changed, 91 insertions(+), 40 deletions(-) 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() diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 4229fcea..fcfab1da 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -5,6 +5,18 @@ from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' + item_margin = fields.Float( + 'Margin', compute='compute_item_margin', + help="Total Margin in Sales Order Header") + item_percent_margin = fields.Float( + 'Margin%', compute='compute_item_margin', + help="Total % Margin in Sales Order Header") + so_item_margin = fields.Float( + 'SO Margin', compute='compute_item_margin', + help="Total Margin in Sales Order Header") + so_item_percent_margin = fields.Float( + 'SO Margin%', compute='compute_item_margin', + help="Total % Margin in Sales Order Header") # Override method from addons/purchase/models/purchase.py @api.onchange('product_qty', 'product_uom') @@ -27,37 +39,43 @@ class PurchaseOrderLine(models.Model): self.price_unit = price_unit return res - # def compute_item_margin(self): - # for line in self: - # if not line.product_id or line.price_unit <= 0 or line.product_uom_qty <= 0 or line.product_id.type == 'service' or not line.order_id.sale_order_id.id: - # line.item_margin = 0 - # line.item_percent_margin = 0 - # continue - # 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 = 0 - # real_tax_amount = 0 - # 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: - # raise UserError("Beda tax amount dengan Sales") - # - # # untaxed sales price - # sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty - # # must add expedition price in sales_price, expedition payed by customer? - # # sales_price -= round((line.order_id.sale_order_id.delivery_amount / line.order_id.sale_order_id.count_line_product), 2) - # # untaxed purchase price - # purchase_price = line.price_subtotal - # # must add expedition price in purchase_price as expenses - # purchase_price += round((line.order_id.delivery_amount / line.order_id.count_line_product), 2) - # margin_per_item = sales_price - purchase_price - # line.item_margin = margin_per_item - # if sales_price > 0: - # line.item_percent_margin = round((margin_per_item / sales_price), 2) * 100 \ No newline at end of file + 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': + line.so_item_margin = 0 + line.so_item_percent_margin = 0 + line.item_margin = 0 + line.item_percent_margin = 0 + continue + 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') + # calculate margin so and real margin + # margin so compare est purchase price vs sales price + # real margin compare purchase price vs sales price + line.so_item_margin = sale_order_line.item_margin + line.so_item_percent_margin = sale_order_line.item_percent_margin + sum_so_margin += sale_order_line.item_margin + + sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty + # minus with delivery if covered by indoteknik + 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) + # add with delivery amount in sales price or purchase price if any + 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 + + if sum_so_margin > 0 and sum_sales_price > 0 and sum_margin > 0: + self.order_id.total_so_margin = sum_so_margin + self.order_id.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 + self.order_id.total_margin = sum_margin + self.order_id.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d1200de2..1442b432 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -25,7 +25,7 @@ class SaleOrder(models.Model): shipping_cost_covered = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') - ], string='Shipping Paid by', help='Siapa yang menanggung biaya ekspedisi?', copy=False) + ], string='Shipping Covered by', help='Siapa yang menanggung biaya ekspedisi?', copy=False) shipping_paid_by = fields.Selection([ ('indoteknik', 'Indoteknik'), ('customer', 'Customer') @@ -91,9 +91,9 @@ class SaleOrder(models.Model): self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 377): # vita approval1 += 1 if approval2 > 0: - raise UserError("Harus diapprove oleh Pimpinan (Akbar / Tyas)") + raise UserError("Harus diapprove oleh Pimpinan") elif approval1 > 0: - raise UserError("Harus diapprove oleh Manager (?)") + raise UserError("Harus diapprove oleh Manager") order.approval_status = 'approved' return res @@ -125,7 +125,6 @@ class SaleOrder(models.Model): @api.onchange('sales_tax_id') def onchange_sales_tax_id(self): for line in self.order_line: - # line.tax_id = self.sales_tax_id line.product_id_change() @@ -183,6 +182,6 @@ class SaleOrderLine(models.Model): def product_id_change(self): for line in self: super(SaleOrderLine, self).product_id_change() - if line.product_id: + if line.product_id and line.product_id.type == 'product': line.tax_id = line.order_id.sales_tax_id diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 37b9c0cb..e1f6560c 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -24,6 +24,18 @@ + + + + + + + + + + + + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 17902aca..297d0045 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -16,10 +16,10 @@ - + -- 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 +++++++++++++----------- 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 -- 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/__manifest__.py | 3 ++- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/purchase_order.py | 14 ++++++++------ indoteknik_custom/models/users.py | 10 ++++++++++ indoteknik_custom/views/users.xml | 17 +++++++++++++++++ 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 indoteknik_custom/models/users.py create mode 100644 indoteknik_custom/views/users.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 937fb0c9..0d6da7f1 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -38,10 +38,11 @@ 'views/stock_location.xml', 'views/stock_picking.xml', 'views/stock_picking_type.xml', + 'views/users.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', - 'report/purchase_order.xml' + 'report/purchase_order.xml', ], 'demo': [], 'css': [], diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index e4913205..19916fd4 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -24,3 +24,4 @@ from . import stock_move from . import stock_picking from . import stock_picking_type from . import delivery_order +from . import users 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' diff --git a/indoteknik_custom/models/users.py b/indoteknik_custom/models/users.py new file mode 100644 index 00000000..bc56fe54 --- /dev/null +++ b/indoteknik_custom/models/users.py @@ -0,0 +1,10 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError + + +class Users(models.Model): + _inherit = 'res.users' + + is_purchasing_manager = fields.Boolean(String='Purchasing Manager', help='Berhak melakukan Approval PO') + is_sales_manager = fields.Boolean(String='Sales Manager', help='Berhak melakukan Approval SO dengan margin 15-25') + is_leader = fields.Boolean(String='Leader', help='Berhak Approval SO Margin < 15 dan Approval PO') diff --git a/indoteknik_custom/views/users.xml b/indoteknik_custom/views/users.xml new file mode 100644 index 00000000..d75b35fc --- /dev/null +++ b/indoteknik_custom/views/users.xml @@ -0,0 +1,17 @@ + + + + + User + res.users + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 4eff0ccadaade5964fec515a90bb0fc4c915b917 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 09:00:56 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 1442b432..9f70f05b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -54,11 +54,9 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if (line.item_percent_margin <= 15) and ( - self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas + if line.item_percent_margin <= 15 and not self.env.user.is_leader: # akbar or tyas approval2 += 1 - elif line.item_percent_margin <= 25 and ( - self.env.user.id != 19 and self.env.user.id != 6 and self.env.user.id != 7): + elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: approval1 += 1 if approval2 > 0: order.approval_status = 'pengajuan2' @@ -84,11 +82,9 @@ class SaleOrder(models.Model): raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) if not line.product_id or line.product_id.type == 'service': continue - if (line.item_percent_margin <= 15) and ( - self.env.user.id != 6 and self.env.user.id != 7): # akbar or tyas will approve + if line.item_percent_margin <= 15 and not self.env.user.is_pimpinan: approval2 += 1 - elif line.item_percent_margin <= 25 and ( - self.env.user.id != 6 and self.env.user.id != 7 and self.env.user.id != 377): # vita + elif line.item_percent_margin <= 25 and not self.env.user.is_pimpinan and not self.env.user.is_sales_manager: approval1 += 1 if approval2 > 0: raise UserError("Harus diapprove oleh Pimpinan") -- 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 ++++++++++++++++++++++--- indoteknik_custom/models/purchase_order_line.py | 13 --------- 2 files changed, 31 insertions(+), 17 deletions(-) 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() diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 4965b507..19c2c8fa 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -51,31 +51,18 @@ class PurchaseOrderLine(models.Model): 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') - # calculate margin so and real margin - # margin so compare est purchase price vs sales price - # real margin compare purchase price vs sales price line.so_item_margin = sale_order_line.item_margin line.so_item_percent_margin = sale_order_line.item_percent_margin sum_so_margin += sale_order_line.item_margin - sales_price = sale_order_line.price_reduce_taxexcl * sale_order_line.product_uom_qty - # minus with delivery if covered by indoteknik 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) - # add with delivery amount in sales price or purchase price if any 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 - - if sum_so_margin > 0 and sum_sales_price > 0 and sum_margin > 0: - self.order_id.total_so_margin = sum_so_margin - self.order_id.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 - self.order_id.total_margin = sum_margin - self.order_id.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 -- 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 +-- indoteknik_custom/models/sale_order.py | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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: diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9f70f05b..4ab8aa17 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -95,16 +95,20 @@ class SaleOrder(models.Model): def compute_total_margin(self): for order in self: - total_margin = total_percent_margin = 0 + total_margin = total_percent_margin = sum_sales_price = 0 for line in order.order_line: if not line.product_id: order.total_margin = 0 order.total_percent_margin = 0 continue total_margin += line.item_margin + sales_price = line.price_reduce_taxexcl * line.product_uom_qty + if line.order_id.shipping_cost_covered == 'indoteknik': + sales_price -= round((line.order_id.delivery_amt / line.order_id.count_line_product), 2) + sum_sales_price += sales_price order.total_margin = total_margin if order.amount_untaxed > 0: - total_percent_margin = round((total_margin / order.amount_untaxed), 2) * 100 + total_percent_margin = round((total_margin / sum_sales_price), 2) * 100 order.total_percent_margin = total_percent_margin def compute_count_line_product(self): -- 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 +- indoteknik_custom/models/sale_order.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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 diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 4ab8aa17..f1f281a8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -76,15 +76,15 @@ class SaleOrder(models.Model): raise UserError("Tax di Header harus diisi") approval1 = approval2 = 0 for line in order.order_line: + if not line.product_id or line.product_id.type == 'service': + continue if line.product_id.id == 232383: raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if not line.product_id or line.product_id.type == 'service': - continue - if line.item_percent_margin <= 15 and not self.env.user.is_pimpinan: + if line.item_percent_margin <= 15 and not self.env.user.is_leader: approval2 += 1 - elif line.item_percent_margin <= 25 and not self.env.user.is_pimpinan and not self.env.user.is_sales_manager: + elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: approval1 += 1 if approval2 > 0: raise UserError("Harus diapprove oleh Pimpinan") -- cgit v1.2.3 From fca62b9b9a56f92abffd624067ee75c64f1c84fa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 11:42:31 +0700 Subject: Update sale_order.py and sale_order.xml --- indoteknik_custom/models/sale_order.py | 4 ++++ indoteknik_custom/views/sale_order.xml | 1 + 2 files changed, 5 insertions(+) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index f1f281a8..6410c150 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -46,6 +46,8 @@ class SaleOrder(models.Model): raise UserError("Status harus draft atau sent") if not order.sales_tax_id: raise UserError("Tax di Header harus diisi") + if not order.carrier_id: + raise UserError("Shipping Method harus diisi") approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': @@ -74,6 +76,8 @@ class SaleOrder(models.Model): for order in self: if not order.sales_tax_id: raise UserError("Tax di Header harus diisi") + if not order.carrier_id: + raise UserError("Shipping Method harus diisi") approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 297d0045..0abbae94 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -20,6 +20,7 @@ + -- cgit v1.2.3 From 78811641ffa04c7930fe450f9222d21b5dfceb62 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 16:21:52 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6410c150..6e16c63e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1,5 +1,6 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError +from odoo.tools.misc import formatLang, get_lang import warnings @@ -184,8 +185,7 @@ class SaleOrderLine(models.Model): @api.onchange('product_id') def product_id_change(self): + super(SaleOrderLine, self).product_id_change() for line in self: - super(SaleOrderLine, self).product_id_change() if line.product_id and line.product_id.type == 'product': line.tax_id = line.order_id.sales_tax_id - -- cgit v1.2.3 From 156507bd6de73802ae9ef32d344c59184e6f923a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 29 Sep 2022 17:59:26 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 46 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6e16c63e..5c868c67 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -49,7 +49,7 @@ class SaleOrder(models.Model): raise UserError("Tax di Header harus diisi") if not order.carrier_id: raise UserError("Shipping Method harus diisi") - approval1 = approval2 = 0 + # approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': continue @@ -57,13 +57,19 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if line.item_percent_margin <= 15 and not self.env.user.is_leader: # akbar or tyas - approval2 += 1 - elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: - approval1 += 1 - if approval2 > 0: + # if line.item_percent_margin <= 15 and not self.env.user.is_leader: # akbar or tyas + # approval2 += 1 + # elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + # approval1 += 1 + # if approval2 > 0: + # order.approval_status = 'pengajuan2' + # elif approval1 > 0: + # order.approval_status = 'pengajuan1' + # else: + # raise UserError("Bisa langsung Confirm") + if order.total_percent_margin <= 15 and not self.env.user.is_leader: order.approval_status = 'pengajuan2' - elif approval1 > 0: + elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: order.approval_status = 'pengajuan1' else: raise UserError("Bisa langsung Confirm") @@ -79,7 +85,7 @@ class SaleOrder(models.Model): raise UserError("Tax di Header harus diisi") if not order.carrier_id: raise UserError("Shipping Method harus diisi") - approval1 = approval2 = 0 + # approval1 = approval2 = 0 for line in order.order_line: if not line.product_id or line.product_id.type == 'service': continue @@ -87,15 +93,22 @@ class SaleOrder(models.Model): raise UserError(_('Tidak bisa Confirm menggunakan Produk Sementara')) if not line.vendor_id or not line.purchase_price or not line.purchase_tax_id: raise UserError(_('Isi Vendor, Harga Beli, dan Tax sebelum Request Approval')) - if line.item_percent_margin <= 15 and not self.env.user.is_leader: - approval2 += 1 - elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: - approval1 += 1 - if approval2 > 0: + # if line.item_percent_margin <= 15 and not self.env.user.is_leader: + # approval2 += 1 + # elif line.item_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: + # approval1 += 1 + # if approval2 > 0: + # raise UserError("Harus diapprove oleh Pimpinan") + # elif approval1 > 0: + # raise UserError("Harus diapprove oleh Manager") + # order.approval_status = 'approved' + if order.total_percent_margin <= 15 and not self.env.user.is_leader: raise UserError("Harus diapprove oleh Pimpinan") - elif approval1 > 0: + elif order.total_percent_margin <= 25 and not self.env.user.is_leader and not self.env.user.is_sales_manager: raise UserError("Harus diapprove oleh Manager") - order.approval_status = 'approved' + else: + order.approval_status = 'approved' + return res def compute_total_margin(self): @@ -188,4 +201,7 @@ class SaleOrderLine(models.Model): super(SaleOrderLine, self).product_id_change() for line in self: if line.product_id and line.product_id.type == 'product': + purchase_price = self.env['purchase.pricelist'].search( + [('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 -- 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 +++++++++++++++---------- indoteknik_custom/models/purchase_order_line.py | 14 ++++++++-- indoteknik_custom/models/sale_order.py | 11 ++++++-- 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 @@ + -- cgit v1.2.3 From 1125688c0ce2708ef50a252c0aa0e31a1b0cea25 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 1 Oct 2022 09:23:06 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index fda76ebb..5933e1ae 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -121,7 +121,7 @@ class SaleOrder(models.Model): total_margin += line.item_margin sales_price = line.price_reduce_taxexcl * line.product_uom_qty 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 sum_sales_price += sales_price order.total_margin = total_margin if order.amount_untaxed > 0: -- cgit v1.2.3 From 70c227cff8a3891b4b15b0e8b97ae81beac6a41a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 3 Oct 2022 09:25:46 +0700 Subject: Update purchase_order.xml --- indoteknik_custom/views/purchase_order.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index d0bd515f..a8b71d5a 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -24,13 +24,6 @@ - - - - - - - -- cgit v1.2.3 From 1d6351cbab4df3a5f5ceff92c53560437d7b40a4 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 3 Oct 2022 18:25:08 +0700 Subject: Update sale_order.py --- indoteknik_custom/models/sale_order.py | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5933e1ae..87ed0047 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -212,3 +212,77 @@ class SaleOrderLine(models.Model): 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 + + @api.onchange('product_id', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id') + def _onchange_discount(self): + if not (self.product_id and self.product_uom and + self.order_id.partner_id and self.order_id.pricelist_id and + self.order_id.pricelist_id.discount_policy == 'without_discount' and + self.env.user.has_group('product.group_discount_per_so_line')): + return + + self.discount = 0.0 + product = self.product_id.with_context( + lang=self.order_id.partner_id.lang, + partner=self.order_id.partner_id, + quantity=self.product_uom_qty, + date=self.order_id.date_order, + pricelist=self.order_id.pricelist_id.id, + uom=self.product_uom.id, + fiscal_position=self.env.context.get('fiscal_position') + ) + + product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order, + uom=self.product_uom.id) + + price, rule_id = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule( + self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id) + new_list_price, currency = self.with_context(product_context)._get_real_price_currency(product, rule_id, + self.product_uom_qty, + self.product_uom, + self.order_id.pricelist_id.id) + new_list_price = product.web_price + + if new_list_price != 0: + if self.order_id.pricelist_id.currency_id != currency: + # we need new_list_price in the same currency as price, which is in the SO's pricelist's currency + new_list_price = currency._convert( + new_list_price, self.order_id.pricelist_id.currency_id, + self.order_id.company_id or self.env.company, self.order_id.date_order or fields.Date.today()) + discount = (new_list_price - price) / new_list_price * 100 + if (discount > 0 and new_list_price > 0) or (discount < 0 and new_list_price < 0): + self.discount = discount + + def _get_display_price(self, product): + # TO DO: move me in master/saas-16 on sale.order + # awa: don't know if it's still the case since we need the "product_no_variant_attribute_value_ids" field now + # to be able to compute the full price + + # it is possible that a no_variant attribute is still in a variant if + # the type of the attribute has been changed after creation. + no_variant_attributes_price_extra = [ + ptav.price_extra for ptav in self.product_no_variant_attribute_value_ids.filtered( + lambda ptav: + ptav.price_extra and + ptav not in product.product_template_attribute_value_ids + ) + ] + if no_variant_attributes_price_extra: + product = product.with_context( + no_variant_attributes_price_extra=tuple(no_variant_attributes_price_extra) + ) + + if self.order_id.pricelist_id.discount_policy == 'with_discount': + return product.with_context(pricelist=self.order_id.pricelist_id.id, uom=self.product_uom.id).price + product_context = dict(self.env.context, partner_id=self.order_id.partner_id.id, date=self.order_id.date_order, uom=self.product_uom.id) + + final_price, rule_id = self.order_id.pricelist_id.with_context(product_context).get_product_price_rule(product or self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_id) + base_price, currency = self.with_context(product_context)._get_real_price_currency(product, rule_id, self.product_uom_qty, self.product_uom, self.order_id.pricelist_id.id) + base_price = product.web_price + if currency != self.order_id.pricelist_id.currency_id: + base_price = currency._convert( + base_price, self.order_id.pricelist_id.currency_id, + self.order_id.company_id or self.env.company, self.order_id.date_order or fields.Date.today()) + # negative discounts (= surcharge) are included in the display price + + return max(base_price, final_price) -- cgit v1.2.3