fix the reference document string
This commit is contained in:
parent
693f80e02b
commit
7296290bdc
@ -555,35 +555,86 @@ class StockReadjustValuation(models.Model):
|
||||
# Enhanced POS Detection
|
||||
is_pos = False
|
||||
pos_order_obj = False
|
||||
pos_session_obj = False
|
||||
|
||||
if move.picking_id:
|
||||
# Check if linked to any POS Order
|
||||
pos_orders = self.env['pos.order'].search([('picking_ids', 'in', move.picking_id.id)], limit=1)
|
||||
# 1. Check Origin for Exact Match (Order or Session)
|
||||
if move.origin:
|
||||
# Try finding Order
|
||||
pos_orders = self.env['pos.order'].search(['|', ('name', '=', move.origin), ('pos_reference', '=', move.origin)], limit=1)
|
||||
if pos_orders:
|
||||
is_pos = True
|
||||
pos_order_obj = pos_orders[0]
|
||||
elif move.picking_id.pos_order_id: # Direct field check if exists
|
||||
pos_session_obj = pos_order_obj.session_id
|
||||
|
||||
# Try finding Session (if not Order)
|
||||
if not is_pos:
|
||||
sessions = self.env['pos.session'].search([('name', '=', move.origin)], limit=1)
|
||||
if sessions:
|
||||
is_pos = True
|
||||
pos_session_obj = sessions[0]
|
||||
|
||||
# 2. Check Picking Links (Direct Fields)
|
||||
if not is_pos and move.picking_id:
|
||||
# Check pos_order_id
|
||||
if 'pos_order_id' in move.picking_id._fields and move.picking_id.pos_order_id:
|
||||
is_pos = True
|
||||
pos_order_obj = move.picking_id.pos_order_id
|
||||
pos_session_obj = pos_order_obj.session_id
|
||||
|
||||
if not is_pos and 'POS' in move.picking_id.name:
|
||||
# Check pos_session_id (if exists on picking)
|
||||
if not is_pos and 'pos_session_id' in move.picking_id._fields and move.picking_id.pos_session_id:
|
||||
is_pos = True
|
||||
pos_session_obj = move.picking_id.pos_session_id
|
||||
|
||||
# 3. Check Picking Origin for Session Name
|
||||
if not is_pos and move.picking_id and move.picking_id.origin:
|
||||
sessions = self.env['pos.session'].search([('name', '=', move.picking_id.origin)], limit=1)
|
||||
if sessions:
|
||||
is_pos = True
|
||||
pos_session_obj = sessions[0]
|
||||
|
||||
# 4. Fallback: Search via picking_ids (Last Resort)
|
||||
if not is_pos and move.picking_id:
|
||||
pos_orders = self.env['pos.order'].search([('picking_ids', 'in', move.picking_id.id)], limit=1)
|
||||
if pos_orders:
|
||||
is_pos = True
|
||||
# If we found an order via consolidated picking, we can't be sure it's the right ORDER,
|
||||
# but we can be reasonably sure it's the right SESSION (if grouping by session).
|
||||
# We will grab the session, but NOT claim it's this specific order unless we have no other info.
|
||||
pos_session_obj = pos_orders[0].session_id
|
||||
# Only set pos_order_obj if we think it implies 1:1
|
||||
# We'll skip setting pos_order_obj here to avoid "Arbitrary Order" confusion, just link Session.
|
||||
|
||||
if not is_pos and move.origin and ('POS' in move.origin or 'Sesi' in move.origin):
|
||||
is_pos = True
|
||||
|
||||
if not is_pos and move.reference and 'POS' in move.reference:
|
||||
is_pos = True
|
||||
# 5. String Detection (Legacy/Weak)
|
||||
if not is_pos:
|
||||
candidates = [move.origin, move.reference, move.picking_id.name]
|
||||
for c in candidates:
|
||||
if c and ('POS' in c or 'Sesi' in c):
|
||||
is_pos = True
|
||||
break
|
||||
|
||||
move_amount = amount
|
||||
if move_amount < 0:
|
||||
debit_acc, credit_acc = credit_acc, debit_acc
|
||||
move_amount = abs(move_amount)
|
||||
|
||||
ref_text = f"{self.name} - Adj for {move.name}"
|
||||
if is_pos:
|
||||
details = []
|
||||
if pos_order_obj:
|
||||
details.append(pos_order_obj.name)
|
||||
if pos_session_obj:
|
||||
details.append(pos_session_obj.name)
|
||||
|
||||
if details:
|
||||
ref_text = f"{self.name} - POS Adj for {move.name} ({' - '.join(details)})"
|
||||
else:
|
||||
ref_text = f"{self.name} - POS Adj for {move.name}"
|
||||
|
||||
move_vals = {
|
||||
'journal_id': self.journal_id.id,
|
||||
'date': self.date_end.date(), # Use End Date for Accounting
|
||||
'ref': f"{self.name} - Adj for {move.name}",
|
||||
'ref': ref_text,
|
||||
'move_type': 'entry',
|
||||
'line_ids': [
|
||||
(0, 0, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user