summaryrefslogtreecommitdiff
path: root/fixco_custom/models/automatic_purchase.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-07-28 11:22:49 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-07-28 11:22:49 +0700
commitece8f2950b6c8fc8b65def8bc70d347fe7157f96 (patch)
treefdd85bcac414aa2ee968ee6f640b010f5d70289d /fixco_custom/models/automatic_purchase.py
parentb48199f0ffefe2ccd43799c06f679f1db96c5334 (diff)
skema buffer stock, cr purchasing job, api cancel so
Diffstat (limited to 'fixco_custom/models/automatic_purchase.py')
-rw-r--r--fixco_custom/models/automatic_purchase.py27
1 files changed, 9 insertions, 18 deletions
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