diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-08-19 10:16:00 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-08-19 10:16:00 +0700 |
| commit | b75b17182b374acc9a70d9cf45a501691428fbfe (patch) | |
| tree | 9ba61a51569ae9eef91223133aa80b5340445d1c | |
| parent | 141fcfd3e70042a0fd8bb8f6bede05dc0317d9f6 (diff) | |
test
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 6 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 5 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 144 | ||||
| -rwxr-xr-x | 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 |
