diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-08-22 12:00:27 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-08-22 12:00:27 +0700 |
| commit | 643564ac2eb00eafc09df85a508f5b1bc9b6fef3 (patch) | |
| tree | b77cc77217e431b08b548e43b2b3bebc9794fb51 | |
| parent | ec2085733e14941ad62808e3e23e4c781a654c0a (diff) | |
cr automatic purchase
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index f5b1baf9..3561fc0f 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -545,6 +545,37 @@ class AutomaticPurchaseLine(models.Model): def _calculate_subtotal(self): for line in self: line.subtotal = line.qty_purchase * line.last_price + + @api.onchange('product_id') + def _onchange_product_id(self): + for line in self: + purchase_price = self.env['purchase.pricelist'].search([ + ('product_id', '=', line.product_id.id), + ('vendor_id', '=', line.partner_id.id) + ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) + vendor_id = purchase_price.vendor_id.id + price, taxes = self._get_valid_purchase_price(purchase_price) + line.last_price = price + line.taxes_id = taxes + line.brand_id = line.product_id.product_tmpl_id.x_manufacture.id + line.partner_id = vendor_id + + def _get_valid_purchase_price(self, purchase_price): + price = 0 + taxes = '' + human_last_update = purchase_price.human_last_update or datetime.min + system_last_update = purchase_price.system_last_update or datetime.min + + if purchase_price.taxes_product_id.type_tax_use == 'purchase': + price = purchase_price.product_price + taxes = purchase_price.taxes_product_id.id + + if system_last_update > human_last_update: + if purchase_price.taxes_system_id.type_tax_use == 'purchase': + price = purchase_price.system_price + taxes = purchase_price.taxes_system_id.id + + return price, taxes class AutomaticPurchaseMatch(models.Model): |
