45 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
from odoo import models, api
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
def _link_to_po_lines(self, po):
"""Map SO lines back to PO lines for proper receipt/delivery linking."""
for sol, pol in zip(self, po.order_line):
# For intercompany automation matching logic if needed later
pass
class StockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
res = super(StockPicking, self).button_validate()
for picking in self:
if picking.picking_type_code == 'outgoing' and picking.sale_id:
# If this is a delivery for an intercompany SA, auto validate the receipt on the caller's side
po = self.env['purchase.order'].sudo().search([('name', '=', picking.sale_id.client_order_ref)], limit=1)
if po and picking.company_id.intercompany_auto_invoice:
# Time to validate PO receipts (for intercompany sync)
# For a real implementation, you would dynamically match stock moves.
# Simulating auto-receipt for simplicity in Week 3 demonstration
receipts = po.picking_ids.filtered(lambda p: p.state not in ['done', 'cancel'])
for receipt in receipts:
receipt.sudo().action_assign()
for move in receipt.move_ids_without_package:
move.quantity = move.product_uom_qty
receipt.sudo().button_validate()
# Auto generate invoice on SO side
picking.sale_id.sudo()._create_invoices()
invoices = picking.sale_id.invoice_ids
for inv in invoices:
inv.action_post()
# Auto generate vendor bill on PO side
po.sudo().action_create_invoice()
bills = po.invoice_ids
for bill in bills:
bill.action_post()
return res