diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-08-09 11:15:44 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-08-09 11:15:44 +0700 |
| commit | 2926fbf40b0aefc5507d35276711227f23f7367e (patch) | |
| tree | 63f854064a7e99f24087136c5f4c7e52c88e4d0b | |
| parent | b4b544fa8bfd92f73c49daed520fa34660630379 (diff) | |
Membuat view dan field di model purchase.order Odoo
| -rw-r--r-- | indoteknik_custom/__manifest__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/purchase_order.py | 27 | ||||
| -rw-r--r-- | indoteknik_custom/views/purchase_order.xml | 23 |
4 files changed, 52 insertions, 0 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index b240df1a..31b30f6f 100644 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -14,6 +14,7 @@ 'views/coupon_program.xml', 'views/product_public_category.xml', 'views/product_template.xml', + 'views/purchase_order.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 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) + diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml new file mode 100644 index 00000000..8c2a3ae3 --- /dev/null +++ b/indoteknik_custom/views/purchase_order.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <data> + <record id="purchase_order_form_view_inherit" model="ir.ui.view"> + <field name="name">Purchase Order</field> + <field name="model">purchase.order</field> + <field name="inherit_id" ref="purchase.purchase_order_form"/> + <field name="arch" type="xml"> + <div class="oe_title" position="after"> + <button name="sale_order_sync" + string="Synchronize Sale Order" + type="object" + class="oe_highlight" + attrs="{'invisible': [('sale_order_id', '=', False)]}" + /> + </div> + <field name="date_order" position="before"> + <field name="sale_order_id"/> + </field> + </field> + </record> + </data> +</odoo>
\ No newline at end of file |
