summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchase_order_line.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-08-10 15:53:35 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-08-10 15:53:35 +0700
commit06180f02fd39a917b46a6218c465c0fe94e37610 (patch)
tree06349e99e7110646188124d0743b0795dd63392d /indoteknik_custom/models/purchase_order_line.py
parent2926fbf40b0aefc5507d35276711227f23f7367e (diff)
Membuat view dan model purchase.pricelist, referensi harga ke purchase.pricelist untuk order_line di purchase.order
Diffstat (limited to 'indoteknik_custom/models/purchase_order_line.py')
-rw-r--r--indoteknik_custom/models/purchase_order_line.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py
new file mode 100644
index 00000000..6b7bbfc1
--- /dev/null
+++ b/indoteknik_custom/models/purchase_order_line.py
@@ -0,0 +1,83 @@
+from odoo import fields, models, api
+from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
+
+
+class PurchaseOrderLine(models.Model):
+ _inherit = 'purchase.order.line'
+
+ # Override method from addons/purchase/models/purchase.py
+ @api.onchange('product_id')
+ def onchange_product_id(self):
+ if not self.product_id:
+ return
+
+ # Reset date, price and quantity since _onchange_quantity will provide default values
+ self.price_unit = self.product_qty = 0.0
+
+ self._product_id_change()
+
+ self._suggest_quantity()
+ self._onchange_quantity()
+
+ # Override method from addons/purchase/models/purchase.py
+ @api.onchange('product_qty', 'product_uom')
+ def _onchange_quantity(self):
+ if not self.product_id:
+ return
+ params = {'order_id': self.order_id}
+ seller = self.product_id._select_seller(
+ partner_id=self.partner_id,
+ quantity=self.product_qty,
+ date=self.order_id.date_order and self.order_id.date_order.date(),
+ uom_id=self.product_uom,
+ params=params)
+
+ if seller or not self.date_planned:
+ self.date_planned = self._get_date_planned(seller).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
+
+ # If not seller, use the standard price. It needs a proper currency conversion.
+ if not seller:
+ po_line_uom = self.product_uom or self.product_id.uom_po_id
+ price_unit = self.env['account.tax']._fix_tax_included_price_company(
+ self.product_id.uom_id._compute_price(self.product_id.standard_price, po_line_uom),
+ self.product_id.supplier_taxes_id,
+ self.taxes_id,
+ self.company_id,
+ )
+ if price_unit and self.order_id.currency_id and self.order_id.company_id.currency_id != self.order_id.currency_id:
+ price_unit = self.order_id.company_id.currency_id._convert(
+ price_unit,
+ self.order_id.currency_id,
+ self.order_id.company_id,
+ self.date_order or fields.Date.today(),
+ )
+
+ self.price_unit = price_unit
+ return
+
+ price_unit = self.env['account.tax']._fix_tax_included_price_company(seller.price,
+ self.product_id.supplier_taxes_id,
+ self.taxes_id,
+ self.company_id) if seller else 0.0
+ if price_unit and seller and self.order_id.currency_id and seller.currency_id != self.order_id.currency_id:
+ price_unit = seller.currency_id._convert(
+ price_unit, self.order_id.currency_id, self.order_id.company_id, self.date_order or fields.Date.today())
+
+ if seller and self.product_uom and seller.product_uom != self.product_uom:
+ price_unit = seller.product_uom._compute_price(price_unit, self.product_uom)
+
+ # Custom script
+ purchase_pricelist = self.env['purchase.pricelist'].search([
+ ('product_id', '=', self.product_id.id),
+ ('vendor_id', '=', self.partner_id.id)
+ ], limit=1)
+ price_unit = purchase_pricelist.product_price
+
+ if not price_unit:
+ product_supplierinfo = self.env['product.supplierinfo'].search([
+ ('product_tmpl_id', '=', self.product_id.product_tmpl_id.id),
+ ('name', '=', self.partner_id.id)
+ ], limit=1)
+ price_unit = product_supplierinfo.price
+
+ self.price_unit = price_unit