36 lines
1.8 KiB
Python
36 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models, fields, api, _
|
|
|
|
class GarmentFinishedGoods(models.Model):
|
|
_name = 'garment.finished.goods'
|
|
_description = 'Finished Goods Inventory by Variant (Style + Color + Size)'
|
|
_order = 'style_id, color_id, size_id'
|
|
|
|
style_id = fields.Many2one('garment.style', string='Garment Style', required=True, index=True)
|
|
color_id = fields.Many2one('garment.color', string='Color', required=True, index=True)
|
|
size_id = fields.Many2one('garment.size', string='Size', required=True, index=True)
|
|
sku = fields.Char(string='Variant SKU', compute='_compute_sku', store=True, index=True)
|
|
|
|
product_id = fields.Many2one('product.product', string='Odoo Variant Product')
|
|
location_id = fields.Many2one('stock.location', string='Warehouse Stock Location')
|
|
|
|
on_hand_qty = fields.Integer(string='On Hand Pieces', default=0)
|
|
reserved_qty = fields.Integer(string='Reserved Pieces', default=0)
|
|
available_qty = fields.Integer(string='Available to Ship', compute='_compute_available_qty', store=True)
|
|
shipped_qty = fields.Integer(string='Total Shipped Pieces', default=0)
|
|
|
|
_variant_uniq = models.Constraint('UNIQUE(style_id, color_id, size_id)', 'Finished Goods variant record already exists!')
|
|
|
|
@api.depends('style_id', 'color_id', 'size_id')
|
|
def _compute_sku(self):
|
|
for rec in self:
|
|
s_name = rec.style_id.name if rec.style_id else 'STYLE'
|
|
c_code = rec.color_id.code if rec.color_id else 'CLR'
|
|
sz_code = rec.size_id.code if rec.size_id else 'SZ'
|
|
rec.sku = f"{s_name}-{c_code}-{sz_code}"
|
|
|
|
@api.depends('on_hand_qty', 'reserved_qty')
|
|
def _compute_available_qty(self):
|
|
for rec in self:
|
|
rec.available_qty = max(0, rec.on_hand_qty - rec.reserved_qty)
|