diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-06-26 06:46:32 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-06-26 06:46:32 +0700 |
| commit | 45dc1483342d9ec195c53711b5194e7ddf88b343 (patch) | |
| tree | a6908a1b38d12504e26f05ee17eb5547be112ce5 | |
| parent | b90e863ebb88d4e4519a1ce5b52481567d7c480f (diff) | |
| parent | 48bf536f0728a07a5f7ad960c7872415957d8e7a (diff) | |
Merge branch 'release' into receipt-approval
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/requisition.py | 41 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 10 | ||||
| -rw-r--r-- | indoteknik_custom/views/requisition.xml | 5 |
4 files changed, 57 insertions, 1 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 9764e0c0..3c6ce46c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -22,9 +22,9 @@ from . import purchase_pricelist from . import res_partner_company_type from . import res_partner from . import res_users +from . import sale_order from . import sale_monitoring_detail from . import sale_monitoring -from . import sale_order from . import sales_outstanding from . import sales_target from . import stock_move 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/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 0c631761..0a794f6d 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -122,6 +122,16 @@ class SaleOrder(models.Model): line_no += 1 line.line_no = line_no # _logger.info('Calculate PO Line No %s' % line.id) + + def write(self, vals): + res = super(SaleOrder, self).write(vals) + + if 'carrier_id' in vals: + for picking in self.picking_ids: + if picking.state == 'assigned': + picking.carrier_id = self.carrier_id + + return res def calculate_so_status_beginning(self): so_state = ['sale'] 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" |
