From b858358ffbdd14c9b56ac96f035bddccae4d872d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 8 Jul 2025 08:58:46 +0700 Subject: skema bills and requisition --- fixco_custom/models/requisition.py | 55 +++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'fixco_custom/models/requisition.py') diff --git a/fixco_custom/models/requisition.py b/fixco_custom/models/requisition.py index 1734abd..b0800ba 100644 --- a/fixco_custom/models/requisition.py +++ b/fixco_custom/models/requisition.py @@ -51,24 +51,31 @@ class Requisition(models.Model): sales_approve = fields.Boolean(string='Approval Status', tracking=3, copy=False) merchandise_approve = fields.Boolean(string='Approval Status', tracking=3, copy=False) + def get_price(self, product): + purchase_pricelist = self.env['purchase.pricelist'].search([ + ('product_id', '=', product) + ], limit=1) + if purchase_pricelist: + return purchase_pricelist.price, purchase_pricelist.vendor_id.id + 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') + # 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: + price, vendor = self.get_price(order_line.product_id.id) 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 + 'partner_id': vendor, + 'price_unit': price, + 'taxes_id': 14, + 'subtotal': price * order_line.product_uom_qty } self.env['requisition.line'].create([param]) @@ -90,8 +97,8 @@ class Requisition(models.Model): self.merchandise_approve = True def create_po_from_requisition(self): - if not self.sales_approve and not self.merchandise_approve: - raise UserError('Harus Di Approve oleh Darren atau Rafly') + # if not self.sales_approve and not self.merchandise_approve: + # raise UserError('Harus Di Approve oleh Darren atau Rafly') if not self.requisition_lines: raise UserError('Tidak ada Lines, belum bisa create PO') if self.is_po: @@ -133,7 +140,8 @@ class Requisition(models.Model): 'picking_type_id': 28, # indoteknik bandengan receipts 'date_order': current_time, 'sale_order_id': self.sale_order_id.id, - 'note_description': 'from Purchase Requisition' + # 'source': 'requisition', + # 'note_description': 'from Purchase Requisition' } domain = [ @@ -148,7 +156,7 @@ class Requisition(models.Model): # i start from zero (0) for i in range(page): new_po = self.env['purchase.order'].create([param_header]) - new_po.name = new_po.name + "/R/" + str(i + 1) + new_po.source = 'requisition' po_ids.append(new_po.id) lines = requisition_line.search( domain, @@ -169,8 +177,8 @@ class Requisition(models.Model): 'taxes_id': tax, } new_po_line = self.env['purchase.order.line'].create([param_line]) - line.current_po_id = new_po.id - line.current_po_line_id = new_po_line.id + # line.current_po_id = new_po.id + # line.current_po_line_id = new_po_line.id self.env['requisition.purchase.match'].create([{ 'requisition_id': self.id, @@ -275,7 +283,6 @@ class RequisitionLine(models.Model): _inherit = ['mail.thread'] requisition_id = fields.Many2one('requisition', string='Ref', required=True, ondelete='cascade', index=True, copy=False) - brand_id = fields.Many2one('x_manufactures', string='Brand') product_id = fields.Many2one('product.product', string='Product', tracking=3,) partner_id = fields.Many2one('res.partner', string='Vendor') qty_purchase = fields.Float(string='Qty Purchase') @@ -318,14 +325,12 @@ class RequisitionLine(models.Model): @api.onchange('product_id') def _onchange_product(self): for line in self: - line.brand_id = line.product_id.product_tmpl_id.x_manufacture.id purchase_pricelist = self.env['purchase.pricelist'].search([ ('product_id', '=', line.product_id.id) - ],order='count_trx_po desc, count_trx_po_vendor desc', limit=1) + ], limit=1) - price, taxes = line._get_valid_purchase_price(purchase_pricelist) - line.price_unit = price - line.taxes_id = taxes + # price, taxes = line._get_valid_purchase_price(purchase_pricelist) + line.price_unit = purchase_pricelist.price line.partner_id = purchase_pricelist.vendor_id.id @api.model @@ -354,10 +359,10 @@ class RequisitionLine(models.Model): message = f"Produk telah di-{action} :
" if action == 'Tambah': # message += f"
Product: {self.product_id.name}" - message += f"Product: {self.product_id.name}
Vendor: {self.partner_id.name}
Qty: {self.qty_purchase}
Price: {self.price_unit}
Tax: {self.tax_id.name}
Subtotal: {self.subtotal}
Brand: {self.brand_id.x_name}" + message += f"Product: {self.product_id.name}
Vendor: {self.partner_id.name}
Qty: {self.qty_purchase}
Price: {self.price_unit}
Tax: {self.tax_id.name}
Subtotal: {self.subtotal}
" elif action == 'Hapus': # message += f"
Deleted Product: {self.product_id.name}" - message += f"
Deleted Product: {self.product_id.name}
Vendor: {self.partner_id.name} Qty: {self.qty_purchase}
Price: {self.price_unit}
Tax: {self.tax_id.name}
Subtotal: {self.subtotal}
Brand: {self.brand_id.x_name}" + message += f"
Deleted Product: {self.product_id.name}
Vendor: {self.partner_id.name} Qty: {self.qty_purchase}
Price: {self.price_unit}
Tax: {self.tax_id.name}
Subtotal: {self.subtotal}
" else: # Updated for field, old_value in old_values.items(): new_value = self[field] -- cgit v1.2.3