From 7059f095dd09649f7c12f74ff29200f644bbc854 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 3 Oct 2024 11:55:16 +0700 Subject: push --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/sale_order.py | 12 ++-- indoteknik_custom/models/sale_order_line.py | 10 +-- indoteknik_custom/models/vendor_approval.py | 14 ++++ indoteknik_custom/security/ir.model.access.csv | 2 + indoteknik_custom/views/vendor_approval.xml | 98 ++++++++++++++++++++++++++ 7 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 indoteknik_custom/views/vendor_approval.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index e1a67592..116c64ec 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -143,6 +143,7 @@ 'views/partner_payment_term.xml', 'views/vendor_payment_term.xml', 'views/approval_unreserve.xml', + 'views/vendor_approval.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 3d700ce0..a0064c06 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -128,3 +128,4 @@ from . import sales_order_reject from . import approval_date_doc from . import account_tax from . import approval_unreserve +from . import vendor_approval diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 538e0209..a6ea6c81 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -78,6 +78,7 @@ class SaleOrder(models.Model): payment_link_midtrans = fields.Char(string='Payment Link', help='Url payment yg digenerate oleh midtrans, harap diserahkan ke customer agar dapat dilakukan pembayaran secara mandiri') payment_qr_code = fields.Binary("Payment QR Code") due_id = fields.Many2one('due.extension', string="Due Extension", readonly=True, tracking=True) + vendor_approval_id = fields.Many2one('vendor.approval', string="Vendor Approval", readonly=True, tracking=True) customer_type = fields.Selection([ ('pkp', 'PKP'), ('nonpkp', 'Non PKP') @@ -104,6 +105,7 @@ class SaleOrder(models.Model): ('cust_procurement', 'Customer Procurement') ], string='Web Approval', copy=False) compute_fullfillment = fields.Boolean(string='Compute Fullfillment', compute="_compute_fullfillment") + vendor_approval = fields.Boolean(string='Vendor Approval') note_ekspedisi = fields.Char(string="Note Ekspedisi") date_kirim_ril = fields.Datetime(string='Tanggal Kirim SJ', compute='_compute_date_kirim', copy=False) date_status_done = fields.Datetime(string='Date Done DO', compute='_compute_date_kirim', copy=False) @@ -703,6 +705,8 @@ class SaleOrder(models.Model): self._validate_order() for order in self: order.order_line.validate_line() + if order.validate_different_vendor() and not self.vendor_approval: + return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') partner = order.partner_id.parent_id or order.partner_id if not partner.property_payment_term_id: @@ -803,12 +807,14 @@ class SaleOrder(models.Model): }).send() def validate_different_vendor(self): - different_vendor = self.order_line.filtered(lambda l: l.vendor_id.id != l.vendor_md_id.id) + different_vendor = self.order_line.filtered(lambda l: l.vendor_id and l.vendor_md_id and l.vendor_id.id != l.vendor_md_id.id) if different_vendor: vendor_approval = self.env['vendor.approval'].create({ 'order_id': self.id, 'state': 'draft', }) + + self.vendor_approval_id = vendor_approval.id for line in self.line: self.env['vendor.approval.line'].create({ 'vendor_approval_id': vendor_approval.id, @@ -823,12 +829,10 @@ class SaleOrder(models.Model): return True else: return False - - def action_confirm(self): for order in self: - if order.validate_partner_invoice_due(): + if order.validate_different_vendor() and not self.vendor_approval: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') order.check_data_real_delivery_address() diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index dca8534c..06b0f53d 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -14,12 +14,9 @@ class SaleOrderLine(models.Model): states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]" ) - vendor_md_id = fields.Many2one( - 'res.partner', string='MD Vendor', readonly=True, - change_default=True, index=True, tracking=1 - ) + vendor_md_id = fields.Many2one('res.partner', string='MD Vendor') purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0) - purchase_price_md = fields.Float('MD Purchase', required=True, digits='Product Price', default=0.0) + purchase_price_md = fields.Float('MD Purchase') 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') fee_third_party_line = fields.Float('FeeThirdPartyLine', compute='compute_fee_third_party_line', default=0) @@ -138,6 +135,7 @@ class SaleOrderLine(models.Model): elif self.product_id.categ_id.id == 34: # finish good / manufacturing only cost = self.product_id.standard_price self.purchase_price = cost + self.purchase_price_md = cost elif self.product_id.x_manufacture.override_vendor_id: # purchase_price = self.env['purchase.pricelist'].search( # [('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id), @@ -145,6 +143,8 @@ class SaleOrderLine(models.Model): # limit=1, order='count_trx_po desc, count_trx_po_vendor desc') price, taxes, vendor_id = self._get_purchase_price_by_vendor(self.product_id, self.vendor_id) self.purchase_price = price + self.purchase_price_md = price + self.vendor_md_id = self.vendor_id self.purchase_tax_id = taxes # else: # purchase_price = self.env['purchase.pricelist'].search( diff --git a/indoteknik_custom/models/vendor_approval.py b/indoteknik_custom/models/vendor_approval.py index 4369a193..442aec7a 100644 --- a/indoteknik_custom/models/vendor_approval.py +++ b/indoteknik_custom/models/vendor_approval.py @@ -15,7 +15,21 @@ class VendorApproval(models.Model): partner_id = fields.Many2one('res.partner', string="Customer", readonly=True) order_id = fields.Many2one('sale.order', string="SO", readonly=True) vendor_approval_line = fields.One2many('vendor.approval.line', 'vendor_approval_id', string='Vendor Approval Lines', auto_join=True) + state = fields.Selection([('draft', 'Draft'), ('done', 'Done'), ('cancel', 'Cancel')], string='State', tracking=True) + + def action_approve(self): + if not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'): + raise UserError('Hanya Merchandiser yang bisa approve') + self.state = 'done' + self.order_id.update({'vendor_approval': True}) + self.order_id.action_confirm() + + def action_reject(self): + if not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'): + raise UserError('Hanya Merchandiser yang bisa cancel') + self.state = 'cancel' + def unlink(self): res = super(VendorApproval, self).unlink() if not self._name == 'vendor.approval': diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 19e3bdca..1cd7c1e9 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -138,3 +138,5 @@ access_approval_date_doc,access.approval.date.doc,model_approval_date_doc,,1,1,1 access_account_tax,access.account.tax,model_account_tax,,1,1,1,1 access_approval_unreserve,access.approval.unreserve,model_approval_unreserve,,1,1,1,1 access_approval_unreserve_line,access.approval.unreserve.line,model_approval_unreserve_line,,1,1,1,1 +access_vendor_approval,access.vendor.approval,model_vendor_approval,,1,1,1,1 +access_vendor_approval_line,access.vendor.approval.line,model_vendor_approval_line,,1,1,1,1 diff --git a/indoteknik_custom/views/vendor_approval.xml b/indoteknik_custom/views/vendor_approval.xml new file mode 100644 index 00000000..c3f5ee77 --- /dev/null +++ b/indoteknik_custom/views/vendor_approval.xml @@ -0,0 +1,98 @@ + + + + + vendor.approval.tree + vendor.approval + + + + + + + + + + + + vendor.approval.line.tree + vendor.approval.line + + + + + + + + + + + + + + vendor.approval.form + vendor.approval + +
+
+
+ + + + + + + + + + + + + + +
+ + +
+
+
+
+ + + vendor.approval.search.view + vendor.approval + + + + + + + + + + + Vendor Approval + ir.actions.act_window + vendor.approval + tree,form + + + +
+
-- cgit v1.2.3