From 9b0ab52b8c1240664567eb8c555dd5d4f3ece677 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 17 May 2023 11:22:16 +0700 Subject: add validation for prevent bug manufacturing order --- indoteknik_custom/models/__init__.py | 3 ++- indoteknik_custom/models/manufacturing.py | 34 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/manufacturing.py diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 5dc9ce9e..18f46d34 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -60,4 +60,5 @@ from . import automatic_purchase from . import apache_solr from . import raja_ongkir from . import procurement_monitoring_detail -from . import brand_vendor \ No newline at end of file +from . import brand_vendor +from . import manufacturing diff --git a/indoteknik_custom/models/manufacturing.py b/indoteknik_custom/models/manufacturing.py new file mode 100644 index 00000000..e6e6592c --- /dev/null +++ b/indoteknik_custom/models/manufacturing.py @@ -0,0 +1,34 @@ +from odoo import fields, models, api +from odoo.exceptions import UserError +import logging + +_logger = logging.getLogger(__name__) + +class Manufacturing(models.Model): + _inherit = 'mrp.production' + + def action_confirm(self): + if self._name != 'mrp.production': + return super(Manufacturing, self).action_confirm() + + if self.location_src_id.id != 75: + raise UserError('Component Location hanya bisa di AS/Stock') + elif self.location_dest_id.id != 75: + raise UserError('Finished Product Location hanya bisa di AS/Stock') + + result = super(Manufacturing, self).action_confirm() + return result + + def button_mark_done(self): + if self._name != 'mrp.production': + return super(Manufacturing, self).button_mark_done() + + for line in self.move_raw_ids: + if line.quantity_done > 0 and line.quantity_done != self.product_uom_qty: + raise UserError('Qty Consume per Line tidak sama dengan Qty to Produce') + if line.forecast_availability != line.product_uom_qty: + raise UserError('Qty Reserved belum sesuai dengan yang seharusnya') + + result = super(Manufacturing, self).button_mark_done() + return result + \ No newline at end of file -- cgit v1.2.3