Sistema de gestión multisucursal sobre Odoo 19 Community: módulos matrix_*, guiones de alta de instalaciones, suite de pruebas y documentación.
73 lines
2.9 KiB
Python
73 lines
2.9 KiB
Python
# Part of Matrix. Collina Systems proprietary module.
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class StockWarehouse(models.Model):
|
|
_inherit = 'stock.warehouse'
|
|
|
|
branch_id = fields.Many2one('matrix.branch', string='Sucursal', index=True)
|
|
|
|
|
|
class StockPicking(models.Model):
|
|
_inherit = 'stock.picking'
|
|
|
|
# El aislamiento fino de inventario (quants, lotes) se completa en
|
|
# Fase 3; en Fase 1 se aíslan almacenes y transferencias (ADR-002).
|
|
branch_id = fields.Many2one(
|
|
related='picking_type_id.warehouse_id.branch_id', string='Sucursal',
|
|
store=True, index=True)
|
|
|
|
|
|
class StockQuant(models.Model):
|
|
_inherit = 'stock.quant'
|
|
|
|
# El aislamiento de Fase 1 llegaba al almacén y a la transferencia, que
|
|
# son los envoltorios; lo de dentro —cuánto hay y qué se movió— seguía
|
|
# abierto a cualquier llamada RPC.
|
|
#
|
|
# location_id is required, and stock.location.warehouse_id is a stored
|
|
# compute, so the related chain is stored and searchable. Quants in
|
|
# virtual locations (customer, supplier, inventory adjustment) have no
|
|
# warehouse behind them and therefore no branch: they are nobody's stock
|
|
# and stay out of reach of the branch admins, which is the intent.
|
|
branch_id = fields.Many2one(
|
|
'matrix.branch', related='location_id.warehouse_id.branch_id',
|
|
string='Sucursal', store=True, index=True)
|
|
|
|
|
|
class StockMove(models.Model):
|
|
_inherit = 'stock.move'
|
|
|
|
branch_id = fields.Many2one(
|
|
'matrix.branch', string='Sucursal', compute='_compute_matrix_branch',
|
|
store=True, index=True)
|
|
|
|
@api.depends('location_id.warehouse_id.branch_id',
|
|
'location_dest_id.warehouse_id.branch_id')
|
|
def _compute_matrix_branch(self):
|
|
# One end of a move is almost always a virtual location with no
|
|
# warehouse behind it: an outgoing move carries the branch on its
|
|
# source, an incoming one on its destination. Taking the first of the
|
|
# two that resolves covers both without a special case.
|
|
for move in self:
|
|
move.branch_id = (move.location_id.warehouse_id.branch_id
|
|
or move.location_dest_id.warehouse_id.branch_id)
|
|
|
|
|
|
class StockMoveLine(models.Model):
|
|
_inherit = 'stock.move.line'
|
|
|
|
branch_id = fields.Many2one(
|
|
'matrix.branch', string='Sucursal', compute='_compute_matrix_branch',
|
|
store=True, index=True)
|
|
|
|
@api.depends('location_id.warehouse_id.branch_id',
|
|
'location_dest_id.warehouse_id.branch_id')
|
|
def _compute_matrix_branch(self):
|
|
# Read from its own locations, not from move_id: a move line can
|
|
# outlive its move (inventory adjustments) and its locations can be
|
|
# finer than the move's.
|
|
for line in self:
|
|
line.branch_id = (line.location_id.warehouse_id.branch_id
|
|
or line.location_dest_id.warehouse_id.branch_id)
|