summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-10-03 11:55:16 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-10-03 11:55:16 +0700
commit7059f095dd09649f7c12f74ff29200f644bbc854 (patch)
tree9e7dc3c1e0ca800a1b589cb3c65dddf5ad798894
parent4a69c71eab2d4ea3504a0cf6e3a9ca241be48594 (diff)
push
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rwxr-xr-xindoteknik_custom/models/sale_order.py12
-rw-r--r--indoteknik_custom/models/sale_order_line.py10
-rw-r--r--indoteknik_custom/models/vendor_approval.py14
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv2
-rw-r--r--indoteknik_custom/views/vendor_approval.xml98
7 files changed, 129 insertions, 9 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<odoo>
+ <data>
+ <record id="vendor_approval_tree" model="ir.ui.view">
+ <field name="name">vendor.approval.tree</field>
+ <field name="model">vendor.approval</field>
+ <field name="arch" type="xml">
+ <tree default_order="create_date desc" create="0">
+ <field name="number"/>
+ <field name="partner_id"/>
+ <field name="order_id"/>
+ <field name="state"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="vendor_approval_line_tree" model="ir.ui.view">
+ <field name="name">vendor.approval.line.tree</field>
+ <field name="model">vendor.approval.line</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="product_id"/>
+ <field name="product_uom_qty"/>
+ <field name="vendor_id"/>
+ <field name="vendor_md_id"/>
+ <field name="purchase_price"/>
+ <field name="purchase_price_md"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="vendor_approval_form" model="ir.ui.view">
+ <field name="name">vendor.approval.form</field>
+ <field name="model">vendor.approval</field>
+ <field name="arch" type="xml">
+ <form create="false">
+ <header>
+ <button name="action_approve"
+ string="Approve"
+ type="object"
+ attrs="{'invisible': [('state', '=', 'done')]}"
+ />
+ <button name="action_reject"
+ string="Cancel"
+ type="object"
+ attrs="{'invisible': [('state', '=', 'cancel')]}"
+ />
+ </header>
+ <sheet>
+ <group>
+ <group>
+ <field name="partner_id" readonly="1"/>
+ <field name="order_id" readonly="1"/>
+ <field name="state" readonly="1"/>
+ </group>
+ </group>
+ <notebook>
+ <page string="SO Line">
+ <field name="vendor_approval_line" readonly="1"/>
+ </page>
+ </notebook>
+ </sheet>
+ <div class="oe_chatter">
+ <field name="message_follower_ids" widget="mail_followers"/>
+ <field name="message_ids" widget="mail_thread"/>
+ </div>
+ </form>
+ </field>
+ </record>
+
+ <record id="vendor_approval_view_search" model="ir.ui.view">
+ <field name="name">vendor.approval.search.view</field> <!-- Made the name more descriptive -->
+ <field name="model">vendor.approval</field>
+ <field name="arch" type="xml">
+ <search string="Search Vendor Approval">
+ <field name="number"/>
+ <field name="partner_id"/>
+ <field name="order_id"/>
+ </search>
+ </field>
+ </record>
+
+ <record id="vendor_approval_action" model="ir.actions.act_window">
+ <field name="name">Vendor Approval</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">vendor.approval</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem
+ id="menu_vendor_approval"
+ name="Vendor Approval"
+ parent="sale.product_menu_catalog"
+ sequence="4"
+ action="vendor_approval_action"
+ />
+ </data>
+</odoo>