summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-08-09 11:15:44 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-08-09 11:15:44 +0700
commit2926fbf40b0aefc5507d35276711227f23f7367e (patch)
tree63f854064a7e99f24087136c5f4c7e52c88e4d0b /indoteknik_custom/models
parentb4b544fa8bfd92f73c49daed520fa34660630379 (diff)
Membuat view dan field di model purchase.order Odoo
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/purchase_order.py27
2 files changed, 28 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 5f5dcf1e..8445ec9e 100644
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -11,3 +11,4 @@ from . import stock_vendor
from . import crm_lead
from . import res_users
from . import user_activity_log
+from . import purchase_order
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
new file mode 100644
index 00000000..f01c4752
--- /dev/null
+++ b/indoteknik_custom/models/purchase_order.py
@@ -0,0 +1,27 @@
+from odoo import fields, models, api
+
+
+class PurchaseOrder(models.Model):
+ _inherit = 'purchase.order'
+
+ 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)
+
+ 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)
+