From 9a97cf1790f913a9fcb9ea4744154305d6ca1ced Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 18 Aug 2022 11:42:50 +0700 Subject: sales order approval --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/purchase_order_line.py | 3 + indoteknik_custom/models/sale_order.py | 113 ++++++++++++++++++++++++ indoteknik_custom/views/sale_order.xml | 41 +++++++++ 5 files changed, 159 insertions(+) create mode 100755 indoteknik_custom/models/sale_order.py create mode 100755 indoteknik_custom/views/sale_order.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 58b8a3df..61b51eed 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -30,6 +30,7 @@ 'views/x_product_tags.xml', 'views/stock_vendor.xml', 'views/crm_lead.xml', + 'views/sale_order.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 02e223fd..a94ed2d3 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -16,3 +16,4 @@ from . import purchase_pricelist from . import purchase_order_line from . import sale_monitoring_detail from . import sale_monitoring +from . import sale_order diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 74b46e4c..22d65ee8 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -81,3 +81,6 @@ class PurchaseOrderLine(models.Model): price_unit = product_supplierinfo.price self.price_unit = price_unit + return { + 'warning': {'title': "Warning", 'message': 'ABCDEF', 'type': 'notification'}, + } diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py new file mode 100755 index 00000000..ed2676b8 --- /dev/null +++ b/indoteknik_custom/models/sale_order.py @@ -0,0 +1,113 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError + +import warnings + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + 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.Integer('Approval Status', copy=False) + approval_status = fields.Selection([ + ('pengajuan1', 'Approval Adela'), + ('pengajuan2', 'Approval Tyas'), + ('approved', 'Approved'), + ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) + + def sale_order_approve(self): + for order in self: + for line in order.order_line: + if (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and self.env.user.id != 6: + order.approval_status = "pengajuan2" + break + elif line.item_percent_margin <= 40 and (self.env.user.id != 8 or self.env.user.id != 7): + order.approval_status = 'pengajuan1' + break + else: + raise UserError("Bisa langsung Confirm") + + def action_cancel(self): + cancel_warning = self._show_cancel_wizard() + if cancel_warning: + return { + 'name': _('Cancel Sales Order'), + 'view_mode': 'form', + 'res_model': 'sale.order.cancel', + 'view_id': self.env.ref('sale.sale_order_cancel_view_form').id, + 'type': 'ir.actions.act_window', + 'context': {'default_order_id': self.id}, + 'target': 'new' + } + inv = self.invoice_ids.filtered(lambda inv: inv.state == 'draft') + inv.button_cancel() + for order in self: + order.approval_status = False + return self.write({'state': 'cancel'}) + + def compute_total_margin(self): + for order in self: + total_margin = total_percent_margin = 0 + for line in order.order_line: + total_margin += line.item_margin + order.total_margin = total_margin + total_percent_margin = total_margin / order.amount_untaxed * 100 + order.total_percent_margin = total_percent_margin + + def action_confirm(self): + if self._get_forbidden_state_confirm() & set(self.mapped('state')): + raise UserError(_( + 'It is not allowed to confirm an order in the following states: %s' + ) % (', '.join(self._get_forbidden_state_confirm()))) + + # custom approval start here + for order in self: + for line in order.order_line: + if (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and self.env.user.id != 6: + raise UserError("Need Tyas / Akbar Approval") + elif line.item_percent_margin <= 40 and self.env.user.id != 8: + raise UserError("Need Adela Approval") + order.approval_status = 'approved' + + for order in self.filtered(lambda order: order.partner_id not in order.message_partner_ids): + order.message_subscribe([order.partner_id.id]) + self.write(self._prepare_confirmation_values()) + + # Context key 'default_name' is sometimes propagated up to here. + # We don't need it and it creates issues in the creation of linked records. + context = self._context.copy() + context.pop('default_name', None) + + self.with_context(context)._action_confirm() + if self.env.user.has_group('sale.group_auto_done_setting'): + self.action_done() + # return True + return { + 'warning': {'title': "Warning", 'message': 'ABCDEF', 'type': 'notification'}, + } + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + item_margin = fields.Float( + 'Total Margin', compute='compute_item_margin', + help="Total Margin in Sales Order Header") + item_percent_margin = fields.Float( + 'Total Percent Margin', compute='compute_item_margin', + help="Total % Margin in Sales Order Header") + + def compute_item_margin(self): + for line in self: + 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) + line.item_margin = margin_per_item + line.item_percent_margin = margin_per_item / subtotal_untaxed * 100 diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml new file mode 100755 index 00000000..e0b4ab4d --- /dev/null +++ b/indoteknik_custom/views/sale_order.xml @@ -0,0 +1,41 @@ + + + + + Sale Order + sale.order + + + + + + + + + + + + + + + + + + + + Sale Order + sale.order + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From f5d1be2daf60165d654bf4c32c1fa91ab53a70c9 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 18 Aug 2022 11:47:28 +0700 Subject: add akbar as approval --- 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 ed2676b8..7ffd5179 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -69,7 +69,7 @@ class SaleOrder(models.Model): for line in order.order_line: if (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and self.env.user.id != 6: raise UserError("Need Tyas / Akbar Approval") - elif line.item_percent_margin <= 40 and self.env.user.id != 8: + elif line.item_percent_margin <= 40 and (self.env.user.id != 8 or self.env.user.id != 7): raise UserError("Need Adela Approval") order.approval_status = 'approved' -- cgit v1.2.3 From 141fcfd3e70042a0fd8bb8f6bede05dc0317d9f6 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 18 Aug 2022 11:48:41 +0700 Subject: remove return warning --- indoteknik_custom/models/sale_order.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7ffd5179..d0a4752b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -85,10 +85,7 @@ class SaleOrder(models.Model): self.with_context(context)._action_confirm() if self.env.user.has_group('sale.group_auto_done_setting'): self.action_done() - # return True - return { - 'warning': {'title': "Warning", 'message': 'ABCDEF', 'type': 'notification'}, - } + return True class SaleOrderLine(models.Model): -- cgit v1.2.3 From b75b17182b374acc9a70d9cf45a501691428fbfe Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 19 Aug 2022 10:16:00 +0700 Subject: test --- indoteknik_custom/__manifest__.py | 6 +- indoteknik_custom/models/__init__.py | 5 +- indoteknik_custom/models/sale_order.py | 144 +++++++++++++++---------- indoteknik_custom/security/ir.model.access.csv | 4 +- 4 files changed, 94 insertions(+), 65 deletions(-) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 61b51eed..5120c057 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -16,8 +16,8 @@ 'views/product_template.xml', 'views/purchase_order.xml', 'views/purchase_pricelist.xml', - 'views/sale_monitoring.xml', - 'views/sale_monitoring_detail.xml', + # 'views/sale_monitoring.xml', + # 'views/sale_monitoring_detail.xml', 'views/user_activity_log.xml', 'views/vit_kelurahan.xml', 'views/vit_kecamatan.xml', @@ -30,7 +30,7 @@ 'views/x_product_tags.xml', 'views/stock_vendor.xml', 'views/crm_lead.xml', - 'views/sale_order.xml', + # 'views/sale_order.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index a94ed2d3..0f824714 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -13,7 +13,4 @@ from . import res_users from . import user_activity_log from . import purchase_order from . import purchase_pricelist -from . import purchase_order_line -from . import sale_monitoring_detail -from . import sale_monitoring -from . import sale_order +from . import purchase_order_line \ No newline at end of file diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index d0a4752b..88147042 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -4,8 +4,8 @@ from odoo.exceptions import AccessError, UserError, ValidationError import warnings -class SaleOrder(models.Model): - _inherit = 'sale.order' +class SaleApproval(models.Model): + _inherit = "sale.order" total_margin = fields.Float( 'Total Margin', compute='compute_total_margin', help="Total Margin in Sales Order Header") @@ -21,71 +21,98 @@ class SaleOrder(models.Model): 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 (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and self.env.user.id != 6: - order.approval_status = "pengajuan2" - break - elif line.item_percent_margin <= 40 and (self.env.user.id != 8 or self.env.user.id != 7): - order.approval_status = 'pengajuan1' - break - else: - raise UserError("Bisa langsung Confirm") + 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): - cancel_warning = self._show_cancel_wizard() - if cancel_warning: - return { - 'name': _('Cancel Sales Order'), - 'view_mode': 'form', - 'res_model': 'sale.order.cancel', - 'view_id': self.env.ref('sale.sale_order_cancel_view_form').id, - 'type': 'ir.actions.act_window', - 'context': {'default_order_id': self.id}, - 'target': 'new' - } - inv = self.invoice_ids.filtered(lambda inv: inv.state == 'draft') - inv.button_cancel() - for order in self: - order.approval_status = False - return self.write({'state': 'cancel'}) + # cancel_warning = self._show_cancel_wizard() + # if cancel_warning: + # return { + # 'name': _('Cancel Sales Order'), + # 'view_mode': 'form', + # 'res_model': 'sale.order.cancel', + # 'view_id': self.env.ref('sale.sale_order_cancel_view_form').id, + # 'type': 'ir.actions.act_window', + # 'context': {'default_order_id': self.id}, + # 'target': 'new' + # } + # inv = self.invoice_ids.filtered(lambda inv: inv.state == 'draft') + # inv.button_cancel() + self.approval_status = False + # return self.write({'state': 'cancel'}) + return super(SaleApproval, self).action_cancel def compute_total_margin(self): for order in self: total_margin = total_percent_margin = 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 order.total_margin = total_margin - total_percent_margin = total_margin / order.amount_untaxed * 100 + if order.amount_untaxed > 0: + total_percent_margin = round((total_margin / order.amount_untaxed), 4) * 100 order.total_percent_margin = total_percent_margin - def action_confirm(self): - if self._get_forbidden_state_confirm() & set(self.mapped('state')): - raise UserError(_( - 'It is not allowed to confirm an order in the following states: %s' - ) % (', '.join(self._get_forbidden_state_confirm()))) - - # custom approval start here - for order in self: - for line in order.order_line: - if (line.item_percent_margin <= 15 or line.item_percent_margin == 100) and self.env.user.id != 6: - raise UserError("Need Tyas / Akbar Approval") - elif line.item_percent_margin <= 40 and (self.env.user.id != 8 or self.env.user.id != 7): - raise UserError("Need Adela Approval") - order.approval_status = 'approved' - - for order in self.filtered(lambda order: order.partner_id not in order.message_partner_ids): - order.message_subscribe([order.partner_id.id]) - self.write(self._prepare_confirmation_values()) - - # Context key 'default_name' is sometimes propagated up to here. - # We don't need it and it creates issues in the creation of linked records. - context = self._context.copy() - context.pop('default_name', None) - - self.with_context(context)._action_confirm() - if self.env.user.has_group('sale.group_auto_done_setting'): - self.action_done() - return True + # def action_confirm(self): + # # if self._get_forbidden_state_confirm() & set(self.mapped('state')): + # # raise UserError(_( + # # 'It is not allowed to confirm an order in the following states: %s' + # # ) % (', '.join(self._get_forbidden_state_conf irm()))) + # + # # custom approval start here + # res = super(SaleApproval, 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' + # + # # for order in self.filtered(lambda order: order.partner_id not in order.message_partner_ids): + # # order.message_subscribe([order.partner_id.id]) + # # self.write(self._prepare_confirmation_values()) + # # + # # # Context key 'default_name' is sometimes propagated up to here. + # # # We don't need it and it creates issues in the creation of linked records. + # # context = self._context.copy() + # # context.pop('default_name', None) + # # + # # self.with_context(context)._action_confirm() + # # if self.env.user.has_group('sale.group_auto_done_setting'): + # # self.action_done() + # return res class SaleOrderLine(models.Model): @@ -99,6 +126,10 @@ class SaleOrderLine(models.Model): def compute_item_margin(self): for line in self: + if not line.product_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') @@ -107,4 +138,5 @@ class SaleOrderLine(models.Model): purchase_pricelist_untaxed = purchase_pricelist.product_price / 1.11 margin_per_item = subtotal_untaxed - (purchase_pricelist_untaxed * line.product_uom_qty) line.item_margin = margin_per_item - line.item_percent_margin = margin_per_item / subtotal_untaxed * 100 + if subtotal_untaxed > 0: + line.item_percent_margin = round((margin_per_item / subtotal_untaxed), 4) * 100 diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 08d8b519..c43c17cc 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -8,5 +8,5 @@ access_x_product_tags,access.x.product.tags,model_x_product_tags,,1,1,1,1 access_stock_vendor,access.stock.vendor,model_stock_vendor,,1,1,1,1 access_user_activity_log,access.user.activity.log,model_user_activity_log,,1,1,1,1 access_purchase_pricelist,access.purchase.pricelist,model_purchase_pricelist,,1,1,1,1 -access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1 -access_sale_monitoring_detail,access.sale.monitoring.detail,model_sale_monitoring_detail,,1,1,1,1 \ No newline at end of file +# access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1 +# access_sale_monitoring_detail,access.sale.monitoring.detail,model_sale_monitoring_detail,,1,1,1,1 \ No newline at end of file -- cgit v1.2.3 From 553ddb705044ec7ebe75361a0963564e6cde6b7b Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 19 Aug 2022 11:03:43 +0700 Subject: fix approval sales order with super --- indoteknik_custom/__manifest__.py | 6 +-- indoteknik_custom/models/__init__.py | 5 +- indoteknik_custom/models/sale_order.py | 75 ++++++++------------------ indoteknik_custom/security/ir.model.access.csv | 4 +- 4 files changed, 30 insertions(+), 60 deletions(-) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 5120c057..61b51eed 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -16,8 +16,8 @@ 'views/product_template.xml', 'views/purchase_order.xml', 'views/purchase_pricelist.xml', - # 'views/sale_monitoring.xml', - # 'views/sale_monitoring_detail.xml', + 'views/sale_monitoring.xml', + 'views/sale_monitoring_detail.xml', 'views/user_activity_log.xml', 'views/vit_kelurahan.xml', 'views/vit_kecamatan.xml', @@ -30,7 +30,7 @@ 'views/x_product_tags.xml', 'views/stock_vendor.xml', 'views/crm_lead.xml', - # 'views/sale_order.xml', + 'views/sale_order.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 0f824714..8da36ce1 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -13,4 +13,7 @@ from . import res_users from . import user_activity_log from . import purchase_order from . import purchase_pricelist -from . import purchase_order_line \ No newline at end of file +from . import purchase_order_line +from . import sale_order +from . import sale_monitoring_detail +from . import sale_monitoring diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 88147042..44eeae60 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -4,7 +4,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError import warnings -class SaleApproval(models.Model): +class SaleOrder(models.Model): _inherit = "sale.order" total_margin = fields.Float( 'Total Margin', compute='compute_total_margin', @@ -44,22 +44,8 @@ class SaleApproval(models.Model): raise UserError("Bisa langsung Confirm") def action_cancel(self): - # cancel_warning = self._show_cancel_wizard() - # if cancel_warning: - # return { - # 'name': _('Cancel Sales Order'), - # 'view_mode': 'form', - # 'res_model': 'sale.order.cancel', - # 'view_id': self.env.ref('sale.sale_order_cancel_view_form').id, - # 'type': 'ir.actions.act_window', - # 'context': {'default_order_id': self.id}, - # 'target': 'new' - # } - # inv = self.invoice_ids.filtered(lambda inv: inv.state == 'draft') - # inv.button_cancel() self.approval_status = False - # return self.write({'state': 'cancel'}) - return super(SaleApproval, self).action_cancel + return super(SaleOrder, self).action_cancel() def compute_total_margin(self): for order in self: @@ -75,44 +61,25 @@ class SaleApproval(models.Model): total_percent_margin = round((total_margin / order.amount_untaxed), 4) * 100 order.total_percent_margin = total_percent_margin - # def action_confirm(self): - # # if self._get_forbidden_state_confirm() & set(self.mapped('state')): - # # raise UserError(_( - # # 'It is not allowed to confirm an order in the following states: %s' - # # ) % (', '.join(self._get_forbidden_state_conf irm()))) - # - # # custom approval start here - # res = super(SaleApproval, 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' - # - # # for order in self.filtered(lambda order: order.partner_id not in order.message_partner_ids): - # # order.message_subscribe([order.partner_id.id]) - # # self.write(self._prepare_confirmation_values()) - # # - # # # Context key 'default_name' is sometimes propagated up to here. - # # # We don't need it and it creates issues in the creation of linked records. - # # context = self._context.copy() - # # context.pop('default_name', None) - # # - # # self.with_context(context)._action_confirm() - # # if self.env.user.has_group('sale.group_auto_done_setting'): - # # self.action_done() - # return res + 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 class SaleOrderLine(models.Model): diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index c43c17cc..08d8b519 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -8,5 +8,5 @@ access_x_product_tags,access.x.product.tags,model_x_product_tags,,1,1,1,1 access_stock_vendor,access.stock.vendor,model_stock_vendor,,1,1,1,1 access_user_activity_log,access.user.activity.log,model_user_activity_log,,1,1,1,1 access_purchase_pricelist,access.purchase.pricelist,model_purchase_pricelist,,1,1,1,1 -# access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1 -# access_sale_monitoring_detail,access.sale.monitoring.detail,model_sale_monitoring_detail,,1,1,1,1 \ No newline at end of file +access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1 +access_sale_monitoring_detail,access.sale.monitoring.detail,model_sale_monitoring_detail,,1,1,1,1 \ No newline at end of file -- cgit v1.2.3 From a836a99c12e1ebf4b764810036ecb64183890ad2 Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Fri, 19 Aug 2022 11:38:51 +0700 Subject: Inherit function menggunakan super --- indoteknik_custom/models/purchase_order.py | 1 - indoteknik_custom/models/purchase_order_line.py | 63 +------------------------ 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 2c589d36..cb048182 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -8,7 +8,6 @@ class PurchaseOrder(models.Model): procurement_status = fields.Char(string='Procurement Status', compute='get_procurement_status',readonly=True) def get_procurement_status(self): - for purchase_order in self: product_uom_qty = sum_qty_received = 0 diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 22d65ee8..b4be9ffc 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -5,67 +5,10 @@ from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' - # Override method from addons/purchase/models/purchase.py - @api.onchange('product_id') - def onchange_product_id(self): - if not self.product_id: - return - - # Reset date, price and quantity since _onchange_quantity will provide default values - self.price_unit = self.product_qty = 0.0 - - self._product_id_change() - - self._suggest_quantity() - self._onchange_quantity() - # Override method from addons/purchase/models/purchase.py @api.onchange('product_qty', 'product_uom') def _onchange_quantity(self): - if not self.product_id: - return - params = {'order_id': self.order_id} - seller = self.product_id._select_seller( - partner_id=self.partner_id, - quantity=self.product_qty, - date=self.order_id.date_order and self.order_id.date_order.date(), - uom_id=self.product_uom, - params=params) - - if seller or not self.date_planned: - self.date_planned = self._get_date_planned(seller).strftime(DEFAULT_SERVER_DATETIME_FORMAT) - - # If not seller, use the standard price. It needs a proper currency conversion. - if not seller: - po_line_uom = self.product_uom or self.product_id.uom_po_id - price_unit = self.env['account.tax']._fix_tax_included_price_company( - self.product_id.uom_id._compute_price(self.product_id.standard_price, po_line_uom), - self.product_id.supplier_taxes_id, - self.taxes_id, - self.company_id, - ) - if price_unit and self.order_id.currency_id and self.order_id.company_id.currency_id != self.order_id.currency_id: - price_unit = self.order_id.company_id.currency_id._convert( - price_unit, - self.order_id.currency_id, - self.order_id.company_id, - self.date_order or fields.Date.today(), - ) - - self.price_unit = price_unit - #return - - price_unit = self.env['account.tax']._fix_tax_included_price_company(seller.price, - self.product_id.supplier_taxes_id, - self.taxes_id, - self.company_id) if seller else 0.0 - if price_unit and seller and self.order_id.currency_id and seller.currency_id != self.order_id.currency_id: - price_unit = seller.currency_id._convert( - price_unit, self.order_id.currency_id, self.order_id.company_id, self.date_order or fields.Date.today()) - - if seller and self.product_uom and seller.product_uom != self.product_uom: - price_unit = seller.product_uom._compute_price(price_unit, self.product_uom) - + res = super(PurchaseOrderLine, self)._onchange_quantity() # Custom script purchase_pricelist = self.env['purchase.pricelist'].search([ ('product_id', '=', self.product_id.id), @@ -81,6 +24,4 @@ class PurchaseOrderLine(models.Model): price_unit = product_supplierinfo.price self.price_unit = price_unit - return { - 'warning': {'title': "Warning", 'message': 'ABCDEF', 'type': 'notification'}, - } + return res -- cgit v1.2.3 From 4988c230b5796c029047e62d6d603e3aecf5c052 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 22 Aug 2022 11:25:33 +0700 Subject: temporary comment sales approval --- indoteknik_custom/models/sale_order.py | 91 +++++++++++++++++----------------- indoteknik_custom/views/sale_order.xml | 8 +-- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 44eeae60..50e6baa3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -12,40 +12,39 @@ class SaleOrder(models.Model): total_percent_margin = fields.Float( 'Total Percent Margin', compute='compute_total_margin', help="Total % Margin in Sales Order Header") - # approval_status = fields.Integer('Approval Status', copy=False) approval_status = fields.Selection([ ('pengajuan1', 'Approval Adela'), ('pengajuan2', 'Approval Tyas'), ('approved', 'Approved'), ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) - 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): + # 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 compute_total_margin(self): for order in self: @@ -61,25 +60,25 @@ 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 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 class SaleOrderLine(models.Model): diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index e0b4ab4d..82058837 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -7,10 +7,10 @@ -- cgit v1.2.3 From b18cc1ec5c6ecb7529f0f87d359f4bb09b5a50f8 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 22 Aug 2022 15:08:41 +0700 Subject: add feature close fixed asset --- indoteknik_custom/models/account_asset.py | 12 ++++++++++++ indoteknik_custom/views/account_asset_views.xml | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 indoteknik_custom/models/account_asset.py create mode 100644 indoteknik_custom/views/account_asset_views.xml diff --git a/indoteknik_custom/models/account_asset.py b/indoteknik_custom/models/account_asset.py new file mode 100644 index 00000000..bd5f9adb --- /dev/null +++ b/indoteknik_custom/models/account_asset.py @@ -0,0 +1,12 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError + + +class AccountAsset(models.Model): + _inherit = 'account.asset.asset' + + def action_close_asset(self): + for asset in self: + if asset.value > 0: + raise UserError("Asset masih mempunyai Value") + asset.state = 'close' diff --git a/indoteknik_custom/views/account_asset_views.xml b/indoteknik_custom/views/account_asset_views.xml new file mode 100644 index 00000000..90c53623 --- /dev/null +++ b/indoteknik_custom/views/account_asset_views.xml @@ -0,0 +1,18 @@ + + + + + Account Asset + account.asset.asset + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 2d82c8d8baf38be2349a87c9f8e9919c9e9de78a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 23 Aug 2022 08:23:27 +0700 Subject: add view and model custom asset --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + 2 files changed, 2 insertions(+) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 61b51eed..919a61a2 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -31,6 +31,7 @@ 'views/stock_vendor.xml', 'views/crm_lead.xml', 'views/sale_order.xml', + 'views/account_asset_views.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 8da36ce1..c31f9bf2 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -17,3 +17,4 @@ from . import purchase_order_line from . import sale_order from . import sale_monitoring_detail from . import sale_monitoring +from . import account_asset \ No newline at end of file -- cgit v1.2.3 From 055e68b5c1c20795c569d67d6bf7363c90182470 Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Tue, 23 Aug 2022 09:26:35 +0700 Subject: Create inherit field in account.move model (Tax Invoice Flag) --- indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/account_move.py | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 indoteknik_custom/models/account_move.py diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 8da36ce1..f4b2f27d 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -17,3 +17,4 @@ from . import purchase_order_line from . import sale_order from . import sale_monitoring_detail from . import sale_monitoring +from . import account_move diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py new file mode 100644 index 00000000..224e22ec --- /dev/null +++ b/indoteknik_custom/models/account_move.py @@ -0,0 +1,7 @@ +from odoo import models, api, fields + + +class AccountMove(models.Model): + _inherit = 'account.move' + date_send_fp = fields.Datetime(string="Tanggal Kirim Faktur Pajak") + last_log_fp = fields.Char(string="Log Terakhir Faktur Pajak") -- cgit v1.2.3