Initial commit
This commit is contained in:
33
fusion_inventory_sync/models/product_template.py
Normal file
33
fusion_inventory_sync/models/product_template.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
"""Extend product template with remote inventory visibility."""
|
||||
_inherit = 'product.template'
|
||||
|
||||
sync_mapping_ids = fields.One2many('fusion.product.sync.mapping', 'local_product_id',
|
||||
string='Remote Inventory Links')
|
||||
remote_qty_available = fields.Float(
|
||||
string='Remote On Hand',
|
||||
compute='_compute_remote_stock',
|
||||
store=False,
|
||||
help='Total on-hand quantity at remote locations (Mobility Specialties)')
|
||||
remote_qty_forecast = fields.Float(
|
||||
string='Remote Forecast',
|
||||
compute='_compute_remote_stock',
|
||||
store=False,
|
||||
help='Total forecasted quantity at remote locations')
|
||||
has_remote_mapping = fields.Boolean(
|
||||
string='Has Remote Link',
|
||||
compute='_compute_remote_stock',
|
||||
store=False)
|
||||
|
||||
@api.depends('sync_mapping_ids', 'sync_mapping_ids.remote_qty_available',
|
||||
'sync_mapping_ids.remote_qty_forecast')
|
||||
def _compute_remote_stock(self):
|
||||
for product in self:
|
||||
mappings = product.sync_mapping_ids
|
||||
product.remote_qty_available = sum(mappings.mapped('remote_qty_available'))
|
||||
product.remote_qty_forecast = sum(mappings.mapped('remote_qty_forecast'))
|
||||
product.has_remote_mapping = bool(mappings)
|
||||
Reference in New Issue
Block a user