summaryrefslogtreecommitdiff
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
parent2926fbf40b0aefc5507d35276711227f23f7367e (diff)
Membuat view dan model purchase.pricelist, referensi harga ke purchase.pricelist untuk order_line di purchase.order
-rw-r--r--indoteknik_custom/__manifest__.py1
-rw-r--r--indoteknik_custom/models/__init__.py2
-rw-r--r--indoteknik_custom/models/purchase_order.py34
-rw-r--r--indoteknik_custom/models/purchase_order_line.py83
-rw-r--r--indoteknik_custom/models/purchase_pricelist.py14
-rw-r--r--indoteknik_custom/security/ir.model.access.csv3
-rw-r--r--indoteknik_custom/views/purchase_order.xml2
-rw-r--r--indoteknik_custom/views/purchase_pricelist.xml53
8 files changed, 174 insertions, 18 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index 31b30f6f..8de5bebc 100644
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -15,6 +15,7 @@
'views/product_public_category.xml',
'views/product_template.xml',
'views/purchase_order.xml',
+ 'views/purchase_pricelist.xml',
'views/user_activity_log.xml',
'views/vit_kelurahan.xml',
'views/vit_kecamatan.xml',
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 8445ec9e..30914b52 100644
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -12,3 +12,5 @@ from . import crm_lead
from . import res_users
from . import user_activity_log
from . import purchase_order
+from . import purchase_pricelist
+from . import purchase_order_line
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index f01c4752..ba98d8d3 100644
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -7,21 +7,23 @@ class PurchaseOrder(models.Model):
sale_order_id = fields.Many2one('sale.order', string='Sale Order')
def sale_order_sync(self):
- if self.sale_order_id:
- purchase_orders = self.search(['&', ('sale_order_id', '=', self.sale_order_id.id), ('id', '!=', self.id)])
- products_exception = []
- for purchase_order in purchase_orders:
- for order_line in purchase_order.order_line:
- products_exception.append(order_line.product_id.id)
+ if not self.sale_order_id:
+ return
- self.order_line.unlink()
- for order_line in self.sale_order_id.order_line:
- if order_line.product_id.id and order_line.product_id.id not in products_exception:
- values = {
- 'order_id': self.id,
- 'product_id': order_line.product_id.id,
- 'name': order_line.product_id.name,
- 'product_qty': order_line.product_qty
- }
- self.env['purchase.order.line'].sudo().create(values)
+ purchase_orders = self.search(['&', ('sale_order_id', '=', self.sale_order_id.id), ('id', '!=', self.id)])
+ products_exception = []
+ for purchase_order in purchase_orders:
+ for order_line in purchase_order.order_line:
+ products_exception.append(order_line.product_id.id)
+
+ self.order_line.unlink()
+ for order_line in self.sale_order_id.order_line:
+ if order_line.product_id.id and order_line.product_id.id not in products_exception:
+ values = {
+ 'order_id': self.id,
+ 'product_id': order_line.product_id.id,
+ 'name': order_line.product_id.name,
+ 'product_qty': order_line.product_qty
+ }
+ self.env['purchase.order.line'].sudo().create(values)
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
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
new file mode 100644
index 00000000..25e551ae
--- /dev/null
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -0,0 +1,14 @@
+from odoo import models, fields, api
+
+
+class PurchasePricelist(models.Model):
+ _name = 'purchase.pricelist'
+
+ name = fields.Char(string='Name', compute="_compute_name")
+ product_id = fields.Many2one('product.product', string="Product", required=True)
+ vendor_id = fields.Many2one('res.partner', string="Vendor", required=True)
+ product_price = fields.Float(string='Price', required=True)
+
+ @api.depends('product_id', 'vendor_id')
+ def _compute_name(self):
+ self.name = self.vendor_id.name + ', ' + self.product_id.name
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 510987a8..dc18fd33 100644
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -6,4 +6,5 @@ access_x_manufactures,access.x.manufactures,model_x_manufactures,,1,1,1,1
access_x_partner_purchase_order,access.x.partner.purchase.order,model_x_partner_purchase_order,,1,1,1,1
access_x_product_tags,access.x.product.tags,model_x_product_tags,,1,1,1,1
access_stock_vendor,access.stock.vendor,model_stock_vendor,,1,1,1,1
-access_user_activity_log,access.user.activity.log,model_user_activity_log,,1,1,1,1 \ No newline at end of file
+access_user_activity_log,access.user.activity.log,model_user_activity_log,,1,1,1,1
+access_purchase_pricelist,access.purchase.pricelist,model_purchase_pricelist,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml
index 8c2a3ae3..48a8cf6b 100644
--- a/indoteknik_custom/views/purchase_order.xml
+++ b/indoteknik_custom/views/purchase_order.xml
@@ -10,7 +10,7 @@
<button name="sale_order_sync"
string="Synchronize Sale Order"
type="object"
- class="oe_highlight"
+ class="oe_highlight oe_edit_only"
attrs="{'invisible': [('sale_order_id', '=', False)]}"
/>
</div>
diff --git a/indoteknik_custom/views/purchase_pricelist.xml b/indoteknik_custom/views/purchase_pricelist.xml
new file mode 100644
index 00000000..d6abcec1
--- /dev/null
+++ b/indoteknik_custom/views/purchase_pricelist.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<odoo>
+ <record id="purchase_pricelist_tree" model="ir.ui.view">
+ <field name="name">purchase.pricelist.tree</field>
+ <field name="model">purchase.pricelist</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="product_id"/>
+ <field name="vendor_id"/>
+ <field name="product_price"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="purchase_pricelist_form" model="ir.ui.view">
+ <field name="name">purchase.pricelist.form</field>
+ <field name="model">purchase.pricelist</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet>
+ <group>
+ <group>
+ <field name="product_id"/>
+ <field name="vendor_id" context="{'res_partner_search_mode': 'supplier'}"/>
+ <field name="product_price"/>
+ </group>
+ <group></group>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="purchase_pricelist_action" model="ir.actions.act_window">
+ <field name="name">Purchase Pricelist</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">purchase.pricelist</field>
+ <field name="view_mode">tree,form</field>
+ <field name="help" type="html">
+ <p class="o_view_nocontent_smiling_face">
+ Add Purchase Pricelist!
+ </p>
+ </field>
+ </record>
+
+ <menuitem
+ id="menu_purchase_pricelist"
+ name="Purchase Pricelist"
+ parent="purchase.menu_purchase_products"
+ sequence="3"
+ action="purchase_pricelist_action"
+ />
+</odoo> \ No newline at end of file