diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-11-06 13:49:11 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-11-06 13:49:11 +0700 |
| commit | aab2132ec791085ec02c57a9bba20d46ea48e7f7 (patch) | |
| tree | 25a85ef0832bb7fdb88ec574c210e8b2908c3228 | |
| parent | b3e90d317b993b23c549fc985231a59df9f8c352 (diff) | |
| parent | 7fccc21783e9c3b61c62757b202bccf3b40aba31 (diff) | |
Merge branch 'production' into commision-window
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index f81ecdcc..502761e0 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -105,15 +105,18 @@ class AutomaticPurchase(models.Model): ('product_id', '=', point.product_id.id), # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id), ('vendor_id', '=', self.vendor_id.id) - ], order='product_price asc', limit=1) + ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) else: purchase_price = self.env['purchase.pricelist'].search([ ('product_id', '=', point.product_id.id), # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id), - ], order='product_price asc', limit=1) + ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) vendor_id = purchase_price.vendor_id.id - price = purchase_price.product_price or 0 + price = self._get_valid_purchase_price(purchase_price) + + if self.vendor_id and self.vendor_id.id != vendor_id: + continue self.env['automatic.purchase.line'].create([{ 'automatic_purchase_id': self.id, @@ -135,6 +138,19 @@ class AutomaticPurchase(models.Model): _logger.info('Create Automatic Purchase Line %s' % point.product_id.name) self.notification = "Automatic PO Created %s Lines" % count + def _get_valid_purchase_price(self, purchase_price): + p_price = 0 + if purchase_price.system_price > 0 and purchase_price.product_price > 0: + if purchase_price.human_last_update > purchase_price.system_last_update: + p_price = purchase_price.product_price + else: + p_price = purchase_price.system_price + elif purchase_price.system_price > 0 and purchase_price.product_price == 0: + p_price = purchase_price.system_price + elif purchase_price.system_price == 0 and purchase_price.product_price > 0: + p_price = purchase_price.product_price + return p_price + class AutomaticPurchaseLine(models.Model): _name = 'automatic.purchase.line' |
