diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-03-28 16:43:18 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-03-28 16:43:18 +0700 |
| commit | 2e45cefae9b6f757fd29fb304d6935c1826f2c5b (patch) | |
| tree | 0388048cf64cb5fbe8707b3d57fc2d00fc5ab369 | |
| parent | dd130d106600f48a9b3513c75a298946c8aa0334 (diff) | |
create automatic po from purchase pricelist
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 2b20429a..d34a7aa1 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -56,6 +56,7 @@ class AutomaticPurchase(models.Model): 'automatic_purchase_id': self.id, 'order_id': new_po.id }]) + self.is_po = True def generate_automatic_purchase(self): if self.purchase_lines: @@ -72,6 +73,10 @@ class AutomaticPurchase(models.Model): continue qty_purchase = point.product_max_qty - point.product_id.qty_available po_line = self.env['purchase.order.line'].search([('product_id', '=', point.product_id.id), ('order_id.state', '=', 'done')], limit=1) + purchase_price = self.env['purchase.pricelist'].search([('product_id', '=', point.product_id.id)], order='product_price asc', limit=1) + vendor_id = purchase_price.vendor_id.id + price = purchase_price.product_price + self.env['automatic.purchase.line'].create([{ 'automatic_purchase_id': self.id, 'product_id': point.product_id.id, @@ -79,9 +84,11 @@ class AutomaticPurchase(models.Model): 'qty_min': point.product_min_qty, 'qty_max': point.product_max_qty, 'qty_available': point.product_id.qty_available, - 'partner_id': po_line.order_id.partner_id.id, - 'last_price': po_line.price_unit, - 'subtotal': qty_purchase * po_line.price_unit, + # 'partner_id': po_line.order_id.partner_id.id, + # 'last_price': po_line.price_unit, + 'partner_id': vendor_id, + 'last_price': price, + 'subtotal': qty_purchase * price, 'last_order_id': po_line.order_id.id, 'last_orderline_id': po_line.id }]) |
