diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-01-22 16:58:11 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-01-22 16:58:11 +0700 |
| commit | e5dbcd62560f4083d413d474b123ed971926a2a0 (patch) | |
| tree | 050e1fbb121ae69a8be62dbd7baf3689e6540053 | |
| parent | 53d5d5869f62d73be785400c050b389efb10b511 (diff) | |
final fix bug purchase pricelist
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 17 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 28 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 31 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 26 |
4 files changed, 67 insertions, 35 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 502761e0..7b02a13e 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -89,9 +89,9 @@ class AutomaticPurchase(models.Model): query = [ ('product_min_qty', '>', 0), - ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) + # ('product_id.x_manufacture.user_id.id', '=', self.responsible_id.id) ] - orderpoints = self.env['stock.warehouse.orderpoint'].search(query) + orderpoints = self.env['stock.warehouse.orderpoint'].search(query, limit=100) count = 0 for point in orderpoints: # _logger.info('test %s' % point.product_id.name) @@ -113,7 +113,7 @@ class AutomaticPurchase(models.Model): ], order='count_trx_po desc, count_trx_po_vendor desc', limit=1) vendor_id = purchase_price.vendor_id.id - price = self._get_valid_purchase_price(purchase_price) + price, taxes = self._get_valid_purchase_price(purchase_price) if self.vendor_id and self.vendor_id.id != vendor_id: continue @@ -129,6 +129,7 @@ class AutomaticPurchase(models.Model): # 'last_price': po_line.price_unit, 'partner_id': vendor_id, 'last_price': price, + 'taxes_id': taxes, 'subtotal': qty_purchase * price, 'last_order_id': po_line.order_id.id, 'last_orderline_id': po_line.id, @@ -142,14 +143,19 @@ class AutomaticPurchase(models.Model): 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 + p_price = purchase_price.product_price + taxes = purchase_price.taxes_product_id else: p_price = purchase_price.system_price + taxes = purchase_price.taxes_system_id elif purchase_price.system_price > 0 and purchase_price.product_price == 0: p_price = purchase_price.system_price + taxes = purchase_price.taxes_system_id elif purchase_price.system_price == 0 and purchase_price.product_price > 0: p_price = purchase_price.product_price - return p_price + taxes = purchase_price.taxes_product_id + + return p_price, taxes class AutomaticPurchaseLine(models.Model): @@ -172,6 +178,7 @@ class AutomaticPurchaseLine(models.Model): current_po_id = fields.Many2one('purchase.order', string='Current') current_po_line_id = fields.Many2one('purchase.order.line', string='Current Line') brand_id = fields.Many2one('x_manufactures', string='Brand') + taxes_id = fields.Many2one('x_manufactures', string='Brand') class AutomaticPurchaseMatch(models.Model): diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 7a575748..5303f2c3 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -104,18 +104,18 @@ class PurchaseOrder(models.Model): i += 1 current_time = datetime.utcnow() # print(i, len(self.order_line)) + price_unit = line.price_unit taxes = line.taxes_id - for tax in taxes: - tax_include = tax.price_include - tax_amt = tax.amount - if taxes: - if tax_include: - price_unit = price_unit + (price_unit * tax_amt / 100) - else: - price_unit = price_unit + (price_unit * 11 / 100) - else: - price_unit = price_unit + (price_unit * 11 / 100) + # for tax in taxes: + # tax_include = tax.price_include + # if taxes: + # if tax_include: + # price_unit = price_unit + # else: + # price_unit = price_unit + (price_unit * 11 / 100) + # else: + # price_unit = price_unit + (price_unit * 11 / 100) purchase_pricelist = self.env['purchase.pricelist'].search([ ('product_id', '=', line.product_id.id), @@ -126,13 +126,15 @@ class PurchaseOrder(models.Model): purchase_pricelist.create([{ 'vendor_id': line.order_id.partner_id.id, 'product_id': line.product_id.id, - 'product_price': 0.00, + 'product_price': 0, + 'taxes_system_id': taxes.id, 'system_price': price_unit, - 'system_last_update': current_time, + 'system_last_update': current_time }]) else: purchase_pricelist.write({ 'system_last_update': current_time, + 'taxes_system_id': taxes.id, 'system_price': price_unit }) @@ -303,7 +305,7 @@ class PurchaseOrder(models.Model): if not self.sale_order_id and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Tidak ada link dengan SO, harus approval Manager") send_email = False - # self.add_product_to_pricelist() + self.add_product_to_pricelist() for line in self.order_line: if not line.product_id.purchase_ok: raise UserError("Terdapat barang yang tidak bisa diproses") diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index 807ee628..c7da0e24 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -78,14 +78,12 @@ class PurchaseOrderLine(models.Model): def _onchange_product_custom(self): self._compute_qty_stock() - # Override method from addons/purchase/models/purchase.py - @api.onchange('product_qty', 'product_uom') + @api.onchange('product_id','product_qty', 'product_uom') def _onchange_quantity(self): res = super(PurchaseOrderLine, self)._onchange_quantity() - # Custom script purchase_pricelist = self.env['purchase.pricelist'].search([ ('product_id', '=', self.product_id.id), - ('vendor_id', '=', self.partner_id.id) + ('vendor_id', '=', self.partner_id.id), ], limit=1) price_unit = purchase_pricelist.product_price @@ -96,8 +94,33 @@ class PurchaseOrderLine(models.Model): ], limit=1) price_unit = product_supplierinfo.price + price_unit, taxes = self._get_valid_purchase_price(purchase_pricelist) + self.price_unit = price_unit + if purchase_pricelist.taxes_product_id or purchase_pricelist.taxes_system_id: + self.taxes_id = taxes + return res + + def _get_valid_purchase_price(self, purchase_price): + p_price = 0 + taxes = False + + 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 + taxes = purchase_price.taxes_product_id + else: + p_price = purchase_price.system_price + taxes = purchase_price.taxes_system_id + elif purchase_price.system_price > 0 and purchase_price.product_price == 0: + p_price = purchase_price.system_price + taxes = purchase_price.taxes_system_id + elif purchase_price.system_price == 0 and purchase_price.product_price > 0: + p_price = purchase_price.product_price + taxes = purchase_price.taxes_product_id + + return p_price, taxes def compute_item_margin(self): sum_so_margin = sum_sales_price = sum_margin = 0 diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index b85df109..9c149ea9 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -32,20 +32,20 @@ class PurchasePricelist(models.Model): else: self.human_last_update = current_time - # @api.constrains('system_last_update','system_price') - # def _contrains_include_price(self): - # taxes = self.taxes_system_id or self.taxes_product_id - # tax_include = taxes.price_include - # price_unit = self.system_price or self.product_price - # if taxes: - # if tax_include: - # price_unit = price_unit - # else: - # price_unit = price_unit + (price_unit * 11 / 100) - # else: - # price_unit = price_unit + (price_unit * 11 / 100) + @api.constrains('system_last_update','system_price') + def _contrains_include_price(self): + taxes = self.taxes_system_id or self.taxes_product_id + tax_include = taxes.price_include + price_unit = self.system_price or self.product_price + if taxes: + if tax_include: + price_unit = price_unit + else: + price_unit = price_unit + (price_unit * 11 / 100) + else: + price_unit = price_unit + (price_unit * 11 / 100) - # self.include_price = price_unit + self.include_price = price_unit @api.constrains('vendor_id', 'product_id') def _check_duplicate_purchase_pricelist(self): |
