summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/models/product_template.py45
-rwxr-xr-xindoteknik_custom/models/purchase_order.py34
-rw-r--r--indoteknik_custom/models/requisition.py26
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--indoteknik_custom/views/product_product.xml3
-rw-r--r--indoteknik_custom/views/requisition.xml15
6 files changed, 114 insertions, 10 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index e64b63d7..25473ab8 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -374,6 +374,9 @@ class ProductProduct(models.Model):
is_edited = fields.Boolean(string='Is Edited')
qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold')
short_spesification = fields.Char(string='Short Spesification')
+ max_qty_reorder = fields.Float(string='Max Qty Reorder', compute='_get_max_qty_reordering_rule')
+ qty_rpo = fields.Float(string='Qty RPO', compute='_get_qty_rpo')
+ plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product')
def _get_clean_website_description(self):
for rec in self:
@@ -487,6 +490,16 @@ class ProductProduct(models.Model):
qty = sum(qty_incoming.mapped('product_uom_qty'))
product.qty_incoming_bandengan = qty
+ def _get_qty_incoming_bandengan_with_exclude(self):
+ for product in self:
+ qty_incoming = self.env['stock.move'].search([
+ ('product_id', '=', product.id),
+ ('location_dest_id', 'in', [57, 83]),
+ ('state', 'not in', ['done', 'cancel'])
+ ])
+ qty = sum(qty_incoming.mapped('product_uom_qty'))
+ product.qty_incoming_bandengan = qty
+
def _get_qty_outgoing_bandengan(self):
for product in self:
qty_incoming = self.env['stock.move'].search([
@@ -510,13 +523,41 @@ class ProductProduct(models.Model):
def _get_qty_available_bandengan(self):
for product in self:
qty_available = product.qty_incoming_bandengan + product.qty_onhand_bandengan - product.qty_outgoing_bandengan
- product.qty_available_bandengan = qty_available
+ product.qty_available_bandengan = qty_available or 0
def _get_qty_free_bandengan(self):
for product in self:
qty_free = product.qty_onhand_bandengan - product.qty_outgoing_bandengan
product.qty_free_bandengan = qty_free
-
+
+ def _get_max_qty_reordering_rule(self):
+ for product in self:
+ reordering = self.env['stock.warehouse.orderpoint'].search([
+ ('product_id', '=', product.id)
+ ], limit=1)
+ if not reordering:
+ product.max_qty_reorder = 0
+ else:
+ product.max_qty_reorder = reordering.product_max_qty
+
+ def _get_qty_rpo(self):
+ for product in self:
+ rpo = self.env['v.requisition.match.po'].search([
+ ('product_id', '=', product.id)
+ ], limit=1)
+ if not rpo:
+ product.qty_rpo = 0
+ else:
+ product.qty_rpo = rpo.qty_rpo
+
+ def _get_plafon_qty_product(self):
+ for product in self:
+ qty_available = product.qty_available_bandengan
+ max_qty = product.max_qty_reorder
+ qty_rpo = product.qty_rpo
+ product.plafon_qty = max_qty - qty_available + qty_rpo
+
+
# def write(self, vals):
# if 'solr_flag' not in vals:
# for variant in self:
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index ef86bc61..9faa6464 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -72,6 +72,8 @@ class PurchaseOrder(models.Model):
grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total')
total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match')
approve_by = fields.Many2one('res.users', string='Approve By')
+ exclude_incoming = fields.Boolean(string='Exclude Incoming', default=False,
+ help='Centang jika tidak mau masuk perhitungan Incoming Qty')
def _compute_total_margin_match(self):
for purchase in self:
@@ -583,6 +585,13 @@ class PurchaseOrder(models.Model):
picking.scheduled_date = self.date_planned
picking.date_deadline = self.date_planned
+ def _check_qty_plafon_product(self):
+ for line in self.order_line:
+ if not line.product_id:
+ continue
+ if line.product_uom_qty > line.product_id.plafon_qty and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
+ raise UserError('Product '+line.product_id.name+' melebihi plafon, harus Approval MD')
+
def button_confirm(self):
res = super(PurchaseOrder, self).button_confirm()
current_time = datetime.now()
@@ -635,7 +644,8 @@ class PurchaseOrder(models.Model):
self.date_planned = delta_time
self.date_deadline_ref_date_planned()
self.unlink_purchasing_job_state()
-
+
+ self._check_qty_plafon_product()
return res
@@ -723,8 +733,8 @@ class PurchaseOrder(models.Model):
template.send_mail(self.id, force_send=True)
def po_approve(self):
- if self.amount_untaxed >= 50000000 and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
- raise UserError("Hanya Merchandiser yang bisa approve")
+ # if self.amount_untaxed >= 50000000 and not self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
+ # raise UserError("Hanya Merchandiser yang bisa approve")
if self.env.user.is_leader or self.env.user.has_group('indoteknik_custom.group_role_merchandiser'):
raise UserError("Bisa langsung Confirm")
elif self.total_percent_margin == self.total_so_percent_margin and self.matches_so:
@@ -740,6 +750,10 @@ class PurchaseOrder(models.Model):
reason += 'not link with pj and reorder, '
if not self.matches_so:
reason += 'not link with so, '
+ # Check Plafon Qty and Get Message every Line Product
+ greater_than_plafon, message = self._get_msg_plafon_qty()
+ if greater_than_plafon:
+ reason += message
# Post a highlighted message to lognote
self.message_post(
body=f"<div style='background-color: #fdf2e9; border: 1px solid #f5c6cb; padding: 10px;'>"
@@ -747,6 +761,20 @@ class PurchaseOrder(models.Model):
subtype_id=self.env.ref("mail.mt_note").id
)
+ def _get_msg_plafon_qty(self):
+ message = ''
+ greater_than_plafon = False
+ for line in self.order_line:
+ if not line.product_id:
+ continue
+ if line.product_uom_qty > line.product_id.plafon_qty:
+ message = (message + '\n'+line.product_id.default_code + ' melebihi plafon ('
+ + str(line.product_id.plafon_qty) + ') vs Qty PO ('+str(line.product_uom_qty)+')'
+ + ', ')
+ greater_than_plafon = True
+ print(1)
+ return greater_than_plafon, message
+
def re_calculate(self):
if self.from_apo:
self.re_calculate_from_apo()
diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py
index d53fc796..32a9f94f 100644
--- a/indoteknik_custom/models/requisition.py
+++ b/indoteknik_custom/models/requisition.py
@@ -51,6 +51,27 @@ class Requisition(models.Model):
sales_approve = fields.Boolean(string='Sales Approve', tracking=3, copy=False)
merchandise_approve = fields.Boolean(string='Merchandise Approve', tracking=3, copy=False)
+ def generate_requisition_from_so(self):
+ state = ['done', 'sale']
+ if not self.sale_order_id:
+ raise UserError('Sale Order Wajib Diisi dan Harus Draft')
+ if self.sale_order_id.state in state:
+ raise UserError('SO sudah Confirm, akan berakibat double Purchase melalui PJ')
+ if not self.sale_order_id.order_line:
+ raise UserError('Line SO masih kosong, harus diisi dulu')
+ for order_line in self.sale_order_id.order_line:
+ param = {
+ 'requisition_id': self.id,
+ 'product_id': order_line.product_id.id,
+ 'partner_id': order_line.vendor_id.id,
+ 'qty_purchase': order_line.product_uom_qty,
+ 'price_unit': order_line.purchase_price,
+ 'taxes_id': order_line.purchase_tax_id.id,
+ 'subtotal': order_line.purchase_price * order_line.product_uom_qty,
+ 'brand_id': order_line.product_id.x_manufacture.id
+ }
+ self.env['requisition.line'].create([param])
+
@api.model
def create(self, vals):
vals['number'] = self.env['ir.sequence'].next_by_code('requisition') or '0'
@@ -58,6 +79,9 @@ class Requisition(models.Model):
return result
def button_approve(self):
+ state = ['done', 'sale']
+ if self.sale_order_id.state in state:
+ raise UserError('SO sudah Confirm, akan berakibat double Purchase melalui PJ')
if self.env.user.id not in [377, 19]:
raise UserError('Hanya Vita dan Darren Yang Bisa Approve')
if self.env.user.id == 377:
@@ -76,7 +100,7 @@ class Requisition(models.Model):
raise UserError('Tidak ada Lines, belum bisa create PO')
if self.is_po:
raise UserError('Sudah pernah di create PO')
- if self.sale_order_id:
+ if not self.sale_order_id:
raise UserError('Tidak ada link dengan Sales Order, tidak bisa dihitung sebagai Plafon Qty di PO')
vendor_ids = self.env['requisition.line'].read_group([
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 06848ad7..49b38e6a 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -143,4 +143,5 @@ access_vendor_approval_line,access.vendor.approval.line,model_vendor_approval_li
access_vit_kota,access.vit.kota,model_vit_kota,,1,1,1,1
access_v_brand_product_category,access.v.brand.product.category,model_v_brand_product_category,,1,1,1,1
access_web_find_page,access.web.find.page,model_web_find_page,,1,1,1,1
+access_v_requisition_match_po,access.v.requisition.match.po,model_v_requisition_match_po,,1,1,1,1
access_approval_retur_picking,access.approval.retur.picking,model_approval_retur_picking,,1,1,1,1
diff --git a/indoteknik_custom/views/product_product.xml b/indoteknik_custom/views/product_product.xml
index c06cc5f1..71748e44 100644
--- a/indoteknik_custom/views/product_product.xml
+++ b/indoteknik_custom/views/product_product.xml
@@ -11,11 +11,14 @@
<field name="incoming_qty"/>
</field>
<field name="virtual_available" position="after">
+ <field name="max_qty_reorder" optional="hide"/>
<field name="qty_onhand_bandengan" optional="hide"/>
<field name="qty_incoming_bandengan" optional="hide"/>
<field name="qty_outgoing_bandengan" optional="hide"/>
<field name="qty_available_bandengan" optional="hide"/>
<field name="qty_free_bandengan" optional="hide"/>
+ <field name="qty_rpo" optional="hide"/>
+ <field name="plafon_qty" optional="hide"/>
</field>
</field>
</record>
diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml
index 7b066bca..957113a7 100644
--- a/indoteknik_custom/views/requisition.xml
+++ b/indoteknik_custom/views/requisition.xml
@@ -69,12 +69,19 @@
</group>
<group>
<div>
- <button name="create_po_from_requisition"
- string="Create PO"
- type="object"
- class="mr-2 oe_highlight"
+ <button name="generate_requisition_from_so"
+ string="Create Line from SO"
+ type="object"
+ class="mr-2 oe_highlight"
/>
</div>
+ <div>
+ <button name="create_po_from_requisition"
+ string="Create PO"
+ type="object"
+ class="mr-2 oe_highlight"
+ />
+ </div>
</group>
</group>
<notebook>