diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-06-23 10:33:17 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-06-23 10:33:17 +0700 |
| commit | 046aebc189673851511f90f6291790e652b2cc74 (patch) | |
| tree | 1d446b525ce346b7eea9f5ffbbfbfbd5c63d93e8 | |
| parent | c289fcaf07839dfd965e6113a853026833ff0743 (diff) | |
add button create requistion from sales order with price and calculate subtotal in requisition line
| -rw-r--r-- | indoteknik_custom/models/requisition.py | 41 | ||||
| -rw-r--r-- | indoteknik_custom/views/requisition.xml | 5 |
2 files changed, 46 insertions, 0 deletions
diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 9ae6fb3e..19f0ba7e 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -26,6 +26,43 @@ class Requisition(models.Model): result = super(Requisition, self).create(vals) return result + def create_requisition_from_sales_with_price(self): + if self.requisition_lines: + raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') + if not self.sale_order_id: + raise UserError('Sale Order harus diisi') + if self.is_po: + raise UserError('Sudah jadi PO, tidak bisa di create ulang PO nya') + + count = 0 + for order_line in self.sale_order_id.order_line: + # get purchase price altama, if nothing, then get other cheaper, if nothing then last po + purchase_price = order_line.purchase_price + vendor_id = order_line.vendor_id.id + + # get qty available bandengan + qty_available = order_line.product_id.qty_onhand_bandengan + order_line.product_id.qty_incoming_bandengan - order_line.product_id.outgoing_qty + suggest = 'harus beli' + if qty_available > order_line.product_qty: + suggest = 'masih cukup' + + self.env['requisition.line'].create([{ + 'requisition_id': self.id, + 'partner_id': vendor_id, + 'brand_id': order_line.product_id.product_tmpl_id.x_manufacture.id, + 'product_id': order_line.product_id.id, + 'qty_purchase': order_line.product_uom_qty, + 'tax_id': order_line.purchase_tax_id.id, + 'price_unit': purchase_price, + 'subtotal': purchase_price * order_line.product_uom_qty, + 'source': 'sales', + 'qty_available_store': qty_available, + 'suggest': suggest, + }]) + count+=1 + _logger.info('Create Requisition %s' % order_line.product_id.name) + self.notification = "Requisition Created %s lines" % count + def create_requisition_from_sales(self): if self.requisition_lines: raise UserError('Sudah digenerate sebelumnya, hapus line terlebih dahulu') @@ -182,6 +219,10 @@ class RequisitionLine(models.Model): qty_available_store = fields.Float(string='Available') suggest = fields.Char(string='Suggest') + @api.onchange('price_unit') + def _onchange_price_unit(self): + self.subtotal = self.price_unit * self.qty_purchase + class RequisitionPurchaseMatch(models.Model): _name = 'requisition.purchase.match' _order = 'requisition_id, id' diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml index 9e9440d8..e7335a57 100644 --- a/indoteknik_custom/views/requisition.xml +++ b/indoteknik_custom/views/requisition.xml @@ -67,6 +67,11 @@ type="object" class="mr-2 oe_highlight" /> + <button name="create_requisition_from_sales_with_price" + string="Create Line with Price" + type="object" + class="mr-2 oe_highlight" + /> <button name="create_po_from_requisition" string="Create PO" type="object" |
