From ece8f2950b6c8fc8b65def8bc70d347fe7157f96 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 28 Jul 2025 11:22:49 +0700 Subject: skema buffer stock, cr purchasing job, api cancel so --- fixco_custom/models/automatic_purchase.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 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 d2d6830..037d65a 100644 --- a/fixco_custom/models/automatic_purchase.py +++ b/fixco_custom/models/automatic_purchase.py @@ -108,12 +108,19 @@ class AutomaticPurchase(models.Model): action['views'] = [(self.env.ref('purchase.purchase_order_form').id, 'form')] action['res_id'] = self.purchase_order_ids[0].id return action + + def delete_note_pj(self): + self.env['purchasing.job.note'].search([ + ('product_id', 'in', self.automatic_purchase_lines.mapped('product_id').ids) + ]).unlink() def create_purchase_orders(self): self.ensure_one() if not self.automatic_purchase_lines: raise UserError(_("No purchase lines to process!")) + self.delete_note_pj() + if self.is_po: raise UserError(_("Purchase order already created!")) @@ -162,23 +169,8 @@ class AutomaticPurchase(models.Model): self.is_po = True return self.action_view_purchase_orders() - - def _create_purchase_order(self, vendor, sequence, total_chunks, brand_id=None, category_id=None): - order_name = f"{self.number} - {vendor.name}" - - if brand_id: - brand = self.env['brands'].browse(brand_id) - order_name += f" - {brand.name}" - - if category_id: - cat = self.env['product.public.category'].browse(category_id) - order_name += f" - {cat.name}" - - if total_chunks > 1: - order_name += f" ({sequence}/{total_chunks})" - return self.env['purchase.order'].create({ 'partner_id': vendor.id, 'origin': self.number, @@ -187,7 +179,6 @@ class AutomaticPurchase(models.Model): 'currency_id': vendor.property_purchase_currency_id.id or self.env.company.currency_id.id, 'automatic_purchase_id': self.id, 'source': self.apo_type, - 'name': order_name, }) @@ -377,9 +368,9 @@ class AutomaticPurchaseLine(models.Model): for line in self: if line.product_id: stock_move = self.env['stock.move'].search([ - ('product_id', '=', line.product_id.id), + ('product_id', '=', line.product_id.id), ('location_dest_id', '=', 5), ('location_id', '=', 55), ('state', 'in', ['waiting', 'confirmed', 'assigned', 'partially_available']) - ], limit=1) + ]) line.qty_outgoing = sum(move.product_uom_qty for move in stock_move) \ No newline at end of file -- cgit v1.2.3