CREATE OR REPLACE VIEW public.vw_bi_os_migration_purchase_line AS
 SELECT mm.source_id,
    mm.object_type,
    mm.recon_key,
    mm.tryton_id,
    mm.write_date AS migration_date,
    mm.tryton_model,
    p.number AS tradon_number,
    p.reference AS tradon_reference,
    p.our_reference AS tradon_our_reference,
    p.purchase_date AS tradon_purchase_date,
    pa.name AS tradon_counterparty,
    c.name AS tradon_currency,
    pl.sequence AS tradon_line_number,
    pl.quantity AS tradon_line_quantity,
    pp.code AS tradon_product_code,
    pu.symbol AS tradon_unit_symbol,
    pl.from_del AS tradon_delivery_from_date,
    pl.to_del AS tradon_delivery_to_date
   FROM (((((((os_migration_mapping mm
     JOIN purchase_line pl ON ((pl.id = mm.tryton_id)))
     JOIN purchase_purchase p ON ((pl.purchase = p.id)))
     LEFT JOIN party_party pa ON ((pa.id = p.party)))
     LEFT JOIN currency_currency c ON ((c.id = p.currency)))
     LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
     LEFT JOIN product_product pp ON ((pl.product = pp.id)))
     LEFT JOIN product_uom pu ON ((pl.unit = pu.id)))
  WHERE (mm.tryton_model = '{purchase.line}'::character varying[]);;
