summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/manufacturing.py
blob: 2455a117356eee71a3dc4c660de28afa3fbe8025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from odoo import fields, models, api
from odoo.exceptions import UserError
import logging

_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':
            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
    
    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