110 lines
4.9 KiB
Python
110 lines
4.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models, fields, api, _
|
|
|
|
class GarmentBundle(models.Model):
|
|
_name = 'garment.bundle'
|
|
_inherit = ['mail.thread', 'mail.activity.mixin']
|
|
_description = 'Production Bundle Ticket'
|
|
_order = 'name desc'
|
|
|
|
name = fields.Char(string='Bundle Number', required=True, default=lambda self: _('New'), copy=False, tracking=True)
|
|
barcode = fields.Char(string='Barcode / QR Code', index=True, copy=False)
|
|
|
|
# Parent References
|
|
cutting_plan_id = fields.Many2one('garment.cutting.plan', string='Cutting Order', ondelete='cascade', tracking=True)
|
|
production_plan_id = fields.Many2one('garment.production.plan', string='Production Plan', required=True, tracking=True)
|
|
style_id = fields.Many2one('garment.style', string='Garment Style', required=True)
|
|
color_id = fields.Many2one('garment.color', string='Color', required=True)
|
|
size_id = fields.Many2one('garment.size', string='Size', required=True)
|
|
|
|
# Bundle Contents
|
|
quantity = fields.Integer(string='Bundle Quantity (Pcs)', required=True, default=25, tracking=True)
|
|
ply_start = fields.Integer(string='Ply Start #', default=1)
|
|
ply_end = fields.Integer(string='Ply End #', default=25)
|
|
|
|
# Production Routing Stage
|
|
stage = fields.Selection([
|
|
('cutting', '1. Cutting Room'),
|
|
('sewing', '2. Sewing Assembly'),
|
|
('jobwork', '3. External Processing / Job Work'),
|
|
('quality', '4. Quality Inspection'),
|
|
('packing', '5. Packing Section'),
|
|
('completed', '6. Finished Goods / Packed'),
|
|
], string='Production Stage', default='cutting', tracking=True, required=True)
|
|
|
|
status = fields.Selection([
|
|
('ready', 'Ready for Next Operation'),
|
|
('in_process', 'In Process'),
|
|
('on_hold', 'On Hold (Issue / Defect)'),
|
|
('completed', 'Stage Completed'),
|
|
], string='Status', default='ready', tracking=True)
|
|
|
|
current_line_id = fields.Many2one('garment.sewing.line', string='Assigned Sewing Line')
|
|
current_operator_id = fields.Many2one('res.users', string='Current Operator / Supervisor')
|
|
|
|
history_ids = fields.One2many('garment.bundle.history', 'bundle_id', string='Operation Tracking History')
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if vals.get('name', _('New')) == _('New'):
|
|
vals['name'] = self.env['ir.sequence'].next_by_code('garment.bundle') or _('BND-%s') % fields.Date.today().strftime('%Y%m%d')
|
|
if not vals.get('barcode'):
|
|
vals['barcode'] = vals['name']
|
|
records = super(GarmentBundle, self).create(vals_list)
|
|
for rec in records:
|
|
rec._log_history(rec.stage or 'cutting', 'Bundle Created from Cutting Plies')
|
|
return records
|
|
|
|
def _log_history(self, stage, remarks):
|
|
self.ensure_one()
|
|
self.env['garment.bundle.history'].create({
|
|
'bundle_id': self.id,
|
|
'stage': stage,
|
|
'user_id': self.env.user.id,
|
|
'sewing_line_id': self.current_line_id.id if self.current_line_id else False,
|
|
'quantity': self.quantity,
|
|
'remarks': remarks,
|
|
})
|
|
|
|
def action_move_to_sewing(self):
|
|
self.write({'stage': 'sewing', 'status': 'in_process'})
|
|
self._log_history('sewing', 'Transferred to Sewing Floor')
|
|
|
|
def action_move_to_jobwork(self):
|
|
self.write({'stage': 'jobwork', 'status': 'in_process'})
|
|
self._log_history('jobwork', 'Sent to External Subcontractor')
|
|
|
|
def action_move_to_quality(self):
|
|
self.write({'stage': 'quality', 'status': 'ready'})
|
|
self._log_history('quality', 'Delivered to Quality Inspection Table')
|
|
|
|
def action_move_to_packing(self):
|
|
self.write({'stage': 'packing', 'status': 'ready'})
|
|
self._log_history('packing', 'Quality Passed - Sent to Packing')
|
|
|
|
def action_complete_packing(self):
|
|
self.write({'stage': 'completed', 'status': 'completed'})
|
|
self._log_history('completed', 'Packed into Master Carton')
|
|
|
|
|
|
class GarmentBundleHistory(models.Model):
|
|
_name = 'garment.bundle.history'
|
|
_description = 'Bundle Movement History'
|
|
_order = 'timestamp desc'
|
|
|
|
bundle_id = fields.Many2one('garment.bundle', string='Bundle', required=True, ondelete='cascade')
|
|
timestamp = fields.Datetime(string='Timestamp', default=fields.Datetime.now, required=True)
|
|
stage = fields.Selection([
|
|
('cutting', 'Cutting'),
|
|
('sewing', 'Sewing'),
|
|
('jobwork', 'Job Work'),
|
|
('quality', 'Quality'),
|
|
('packing', 'Packing'),
|
|
('completed', 'Completed'),
|
|
], string='Stage', required=True)
|
|
user_id = fields.Many2one('res.users', string='Scanned / Updated By', default=lambda self: self.env.user)
|
|
sewing_line_id = fields.Many2one('garment.sewing.line', string='Sewing Line')
|
|
quantity = fields.Integer(string='Quantity Passed')
|
|
remarks = fields.Char(string='Remarks / Operation')
|