From 38372fa34198830ea675a471d25cc3523bb1531a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 22 May 2023 15:09:56 +0700 Subject: unbuild validation for prevent negative inventory finished good --- indoteknik_custom/models/manufacturing.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/manufacturing.py b/indoteknik_custom/models/manufacturing.py index 4dbf2605..15756e44 100644 --- a/indoteknik_custom/models/manufacturing.py +++ b/indoteknik_custom/models/manufacturing.py @@ -6,6 +6,7 @@ _logger = logging.getLogger(__name__) class Manufacturing(models.Model): _inherit = 'mrp.production' + unbuild_counter = fields.Integer(string='Unbuild Counter', default=0, help='For restrict unbuild more than once') def action_confirm(self): if self._name != 'mrp.production': @@ -31,4 +32,15 @@ class Manufacturing(models.Model): result = super(Manufacturing, self).button_mark_done() return result - \ No newline at end of file + + def button_unbuild(self): + if self._name != 'mrp.production': + return super(Manufacturing, self).button_unbuild() + + if self.unbuild_counter >= 1: + raise UserError('Tidak bisa unbuild lebih dari 1 kali') + + self.unbuild_counter = self.unbuild_counter + 1 + + result = super(Manufacturing, self).button_unbuild() + return result -- cgit v1.2.3