diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-11-10 08:03:29 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-11-10 08:03:29 +0700 |
| commit | a98d7f339c2bb15974f941b450cbaeb0de64283e (patch) | |
| tree | eebb74483025df03afa1e83e578a7540ab6ba6d7 | |
| parent | 14156f7d6f55eaa4e74310ee1aa4e5128aa17fff (diff) | |
minor change requisition
| -rw-r--r-- | indoteknik_custom/models/requisition.py | 223 | ||||
| -rw-r--r-- | indoteknik_custom/views/requisition.xml | 25 |
2 files changed, 131 insertions, 117 deletions
diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 19f0ba7e..6408c4fd 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -9,6 +9,8 @@ _logger = logging.getLogger(__name__) class Requisition(models.Model): _name = 'requisition' _order = 'id desc' + _inherit = ['mail.thread'] + _rec_name = 'number' number = fields.Char(string='Document No', index=True, copy=False, readonly=True) date_doc = fields.Date(string='Date', help='isi tanggal hari ini') @@ -26,108 +28,108 @@ 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') - 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') + # 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') + # 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') - # old_requisition = self.env['requisition'].search([('sale_order_id', '=', self.sale_order_id.id)], limit=1) - # if old_requisition: - # raise UserError('Sudah pernah jadi Requisition') - - 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 = 0 - vendor_id = 0 - - # 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' - - purchase_pricelist = self.env['purchase.pricelist'].search([ - ('product_id.id', '=', order_line.product_id.id), - ('vendor_id.id', '=', 5571) - ], order='product_price asc', limit=1) - purchase_price = purchase_pricelist.product_price - vendor_id = purchase_pricelist.vendor_id.id - source = 'PriceList' + # # old_requisition = self.env['requisition'].search([('sale_order_id', '=', self.sale_order_id.id)], limit=1) + # # if old_requisition: + # # raise UserError('Sudah pernah jadi Requisition') + + # 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 = 0 + # vendor_id = 0 + + # # 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' + + # purchase_pricelist = self.env['purchase.pricelist'].search([ + # ('product_id.id', '=', order_line.product_id.id), + # ('vendor_id.id', '=', 5571) + # ], order='product_price asc', limit=1) + # purchase_price = purchase_pricelist.product_price + # vendor_id = purchase_pricelist.vendor_id.id + # source = 'PriceList' - if not purchase_price or purchase_price <= 0: - purchase_pricelist = self.env['purchase.pricelist'].search([('product_id', '=', order_line.product_id.id)], order='product_price asc', limit=1) - purchase_price = purchase_pricelist.product_price - vendor_id = purchase_pricelist.vendor_id.id - source = 'PriceList' + # if not purchase_price or purchase_price <= 0: + # purchase_pricelist = self.env['purchase.pricelist'].search([('product_id', '=', order_line.product_id.id)], order='product_price asc', limit=1) + # purchase_price = purchase_pricelist.product_price + # vendor_id = purchase_pricelist.vendor_id.id + # source = 'PriceList' - if not purchase_price or purchase_price <= 0: - last_po_line = self.env['purchase.order.line'].search([('product_id', '=', order_line.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) - purchase_price = last_po_line.price_unit - vendor_id = last_po_line.order_id.partner_id.id - source = 'LastPO' + # if not purchase_price or purchase_price <= 0: + # last_po_line = self.env['purchase.order.line'].search([('product_id', '=', order_line.product_id.id), ('order_id.state', '=', 'done')], order='id desc', limit=1) + # purchase_price = last_po_line.price_unit + # vendor_id = last_po_line.order_id.partner_id.id + # source = 'LastPO' - if not purchase_price or purchase_price <= 0: - purchase_price = 0 - vendor_id = 5571 - source = 'Nothing' - - 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': source, - '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 + # if not purchase_price or purchase_price <= 0: + # purchase_price = 0 + # vendor_id = 5571 + # source = 'Nothing' + + # 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': source, + # '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_po_from_requisition(self): if not self.requisition_lines: @@ -141,13 +143,14 @@ class Requisition(models.Model): for vendor in vendor_ids: param_header = { 'partner_id': vendor['partner_id'][0], - 'partner_ref': self.sale_order_id.name, + # 'partner_ref': self.sale_order_id.name, 'currency_id': 12, 'user_id': self.env.user.id, 'company_id': 1, # indoteknik dotcom gemilang 'picking_type_id': 28, # indoteknik bandengan receipts 'date_order': current_time, - 'sale_order_id': self.sale_order_id.id + 'sale_order_id': self.sale_order_id.id, + 'note_description': 'from Purchase Requisition' } # new_po = self.env['purchase.order'].create([param_header]) products_vendors = self.env['requisition.line'].search([ @@ -156,9 +159,9 @@ class Requisition(models.Model): ('qty_purchase', '>', 0) ], order='brand_id') count = brand_id = 0 - new_po = '' + for product in products_vendors: - if not new_po or ((count == 200 or brand_id != product.brand_id.id) and vendor['partner_id'][0] == 5571): + if count == 200 or brand_id != product.brand_id.id: count = 0 counter_po_number += 1 new_po = self.env['purchase.order'].create([param_header]) @@ -178,14 +181,16 @@ class Requisition(models.Model): if qty_available > product.qty_purchase: suggest = 'masih cukup' + tax = [22] + param_line = { 'order_id': new_po.id, 'sequence': count, 'product_id': product.product_id.id, 'product_qty': product.qty_purchase, 'product_uom_qty': product.qty_purchase, - 'price_unit': product.last_price, - 'taxes_id': product.tax_id, + 'price_unit': product.price_unit, + 'taxes_id': tax, 'qty_available_store': qty_available, 'suggest': suggest, } @@ -193,7 +198,7 @@ class Requisition(models.Model): product.current_po_id = new_po.id product.current_po_line_id = new_line.id _logger.info('Create PO Line %s' % product.product_id.name) - self.notification = self.notification + ' %s' % new_po.name + # self.notification = self.notification + ' %s' % new_po.name self.is_po = True class RequisitionLine(models.Model): @@ -221,7 +226,13 @@ class RequisitionLine(models.Model): @api.onchange('price_unit') def _onchange_price_unit(self): - self.subtotal = self.price_unit * self.qty_purchase + for line in self: + line.subtotal = line.price_unit * line.qty_purchase + + @api.onchange('product_id') + def _onchange_product(self): + for line in self: + line.brand_id = line.product_id.product_tmpl_id.x_manufacture.id class RequisitionPurchaseMatch(models.Model): _name = 'requisition.purchase.match' diff --git a/indoteknik_custom/views/requisition.xml b/indoteknik_custom/views/requisition.xml index e7335a57..e9c3b4e0 100644 --- a/indoteknik_custom/views/requisition.xml +++ b/indoteknik_custom/views/requisition.xml @@ -62,16 +62,6 @@ </group> <group> <div> - <button name="create_requisition_from_sales" - string="Create Line" - 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" @@ -82,13 +72,26 @@ </group> <notebook> <page string="Lines"> - <field name="requisition_lines"/> + <field name="requisition_lines"> + <tree editable="line"> + <field name="product_id"/> + <field name="partner_id"/> + <field name="qty_purchase"/> + <field name="price_unit"/> + <field name="subtotal"/> + <field name="brand_id"/> + </tree> + </field> </page> <page string="Matches"> <field name="requisition_match"/> </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> |
