Skip to content

Instantly share code, notes, and snippets.

@JorgeJuarezM
Created January 3, 2020 22:46
Show Gist options
  • Select an option

  • Save JorgeJuarezM/95053e651f6c7f03baebfceac14f66e6 to your computer and use it in GitHub Desktop.

Select an option

Save JorgeJuarezM/95053e651f6c7f03baebfceac14f66e6 to your computer and use it in GitHub Desktop.

Revisions

  1. JorgeJuarezM created this gist Jan 3, 2020.
    76 changes: 76 additions & 0 deletions Query_HON.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@

    CREATE EXTENSION dblink;

    SELECT dblink_connect('dbname=SYS_BK user=openerp password=1234 host=192.168.50.100');

    select
    -- count(*), date
    *
    from dblink('select id, date, company_id from account_move_line')
    as t1(id integer, date date, company_id integer)
    where t1.id > 15263600 and t1.company_id = 2
    -- group by date
    order by date

    update account_move_line
    set credit = t2.credit, debit = t2.debit
    from (
    SELECT r.res_id, t1.id, t1.credit, t1.debit
    FROM dblink('select id, credit, debit from account_move_line')
    AS t1(id integer, credit numeric, debit numeric)
    inner join migrate_record r
    on r.external_id = t1.id and r.external_table = 'account_move_line'
    ) as t2
    where account_move_line.id = t2.res_id




    select max(external_id) from migrate_record r
    where r.external_table = 'account_move_line'
    and r.state = 'done'




    update migrate_record
    set state = 'done' where res_id > 0




    =====================



    select * from stock_move
    where date >= '2020-01-03'



    select * from stock_location where id in (
    select res_id from migrate_record
    where external_table = 'stock_location'
    ) and name like '%MORELIA%'


    select * from migrate_record
    where res_id in (1458, 1449, 1508)
    and external_table = 'stock_location'








    select * from stock_location where id in (
    select res_id from migrate_record
    where external_id = 19 and external_table = 'stock_location'
    )