From 10e171ea5389873fea3fb13c90242b322a37a990 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 18 Jul 2025 09:25:57 +0700 Subject: On change product otomatis terisi di requisition Create bills by search PO & SKU Create bills by upload --- fixco_custom/models/automatic_purchase.py | 33 ++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'fixco_custom/models/automatic_purchase.py') diff --git a/fixco_custom/models/automatic_purchase.py b/fixco_custom/models/automatic_purchase.py index f3f650d..1ef12ca 100644 --- a/fixco_custom/models/automatic_purchase.py +++ b/fixco_custom/models/automatic_purchase.py @@ -77,7 +77,6 @@ class AutomaticPurchase(models.Model): 'partner_id': vendor.id if vendor else False, 'taxes_id': vendor.tax_id.id if vendor else False, 'price': price, - 'subtotal': subtotal, }) self.env['automatic.purchase.line'].create(lines) @@ -248,7 +247,6 @@ class AutomaticPurchase(models.Model): 'partner_id': stock.vendor_id.id, 'taxes_id': stock.vendor_id.tax_id.id, 'price': price, - 'subtotal': subtotal, }) else: _logger.info( @@ -290,14 +288,35 @@ class AutomaticPurchaseLine(models.Model): qty_outgoing = fields.Float(string='Qty Outgoing', compute='compute_qty_outgoing') partner_id = fields.Many2one('res.partner', string='Vendor') price = fields.Float(string='Price') - subtotal = fields.Float(string='Subtotal') - last_order_id = fields.Many2one('purchase.order', string='Last Order') - last_orderline_id = fields.Many2one('purchase.order.line', string='Last Order Line') + subtotal = fields.Float(string='Subtotal', compute='compute_subtotal') is_po = fields.Boolean(String='Is PO') - current_po_id = fields.Many2one('purchase.order', string='Current') - current_po_line_id = fields.Many2one('purchase.order.line', string='Current Line') taxes_id = fields.Many2one('account.tax', string='Taxes') + def compute_subtotal(self): + for line in self: + line.subtotal = line.qty_purchase * line.price + + @api.onchange('product_id') + def _onchange_product_id(self): + if self.product_id: + manage_stock = self.env['manage.stock'].search([ + ('product_id', '=', self.product_id.id) + ], limit=1) + + if manage_stock: + self.qty_min = manage_stock.min_stock + self.qty_buffer = manage_stock.buffer_stock + self.taxes_id = manage_stock.vendor_id.tax_id.id + self.partner_id = manage_stock.vendor_id.id + + pricelist = self.env['purchase.pricelist'].search([ + ('product_id', '=', self.product_id.id), + ('vendor_id', '=', manage_stock.vendor_id.id) + ], limit=1) + + if pricelist: + self.price = pricelist.price + def compute_qty_available(self): for line in self: if line.product_id: -- cgit v1.2.3