summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-11-12 11:26:13 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-11-12 11:26:13 +0700
commit1f42c0b0adf937e238e68fc2f7307234fff51952 (patch)
treeb039b5dfc1401bce21a3a604c64549a45c3cee52
parent45811de91c682cea9ade1e975f241a651c68b1df (diff)
add button copy so line to requisition
-rw-r--r--indoteknik_custom/models/requisition.py21
-rw-r--r--indoteknik_custom/views/requisition.xml15
2 files changed, 32 insertions, 4 deletions
diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py
index dbf236e2..3aa564df 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'
diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml
index a866690d..16373912 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>