ankdroid

Untitled

Aug 13th, 2025
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 26.67 KB | None | 0 0
  1. from odoo import fields, models, api, tools,_
  2. import logging
  3. from odoo.exceptions import ValidationError
  4.  
  5. _logger = logging.getLogger(__name__)
  6.  
  7.  
  8.  
  9. class CurrentStockDcView(models.Model):
  10.     _name = 'current.stock.dc.view'
  11.     _description = 'current.stock.dc.view'
  12.     _auto = False
  13.     _rec_name = 'id'
  14.  
  15.     category_id = fields.Integer(string='Category ID')
  16.     category_name = fields.Char(string='Category Name')
  17.     product = fields.Char(string='Product')
  18.     branch = fields.Char(string='Branch')
  19.     physical = fields.Integer(string='Physical')
  20.     so_draft = fields.Integer(string='So Draft')
  21.     so_confirm = fields.Integer(string='So Confirm')
  22.     so_waiting = fields.Integer(string='So Waiting')
  23.     so_staging_mnf = fields.Integer(string='So Staging Mnf')
  24.     commit_to_draft = fields.Integer(string='Commit TO Draft')
  25.     commit_to = fields.Integer(string='Commit TO')
  26.     to_satu_branch = fields.Integer(string='TO Satu Branch')
  27.     to_antar_branch = fields.Integer(string='TO Antar Branch')
  28.     mo = fields.Integer(string='MO')
  29.     mo_draft = fields.Integer(string='MO Draft')
  30.     dynamic_reserve = fields.Integer(string='Dynamic Reserve')
  31.     available_spot = fields.Integer(string='Available Spot')
  32.     available_spot_submit = fields.Integer(string='Available Spot Submit')
  33.     available_contract = fields.Integer(string='Available Contract')
  34.     available_contract_submit = fields.Integer(string='Available Contract Submit')
  35.  
  36.     product_category_id = fields.Many2one('attribute.product.category')
  37.     category = fields.Char('Sub Category')
  38.     total_stock = fields.Char('Total Stock')
  39.     psr = fields.Integer(string='PSR')
  40.     psr_draft = fields.Integer(string='PSR draft')
  41.     psr_confirm = fields.Integer(string='PSR Confirm')
  42.  
  43.  
  44.  
  45.     def cron_cancel_commit_to(self):
  46.         _logger.info("---------------------- cron_cancel_commit_to -------------------------")
  47.         query_select_current_stock_dc = """
  48.            select available_contract as available_contract ,
  49.            commit_to as commit_to ,
  50.            product as default_code,
  51.            branch as branch,
  52.            dynamic_reserve as dynamic_reserve
  53.            from current_stock_dc_view csdv
  54.            where available_contract < 0 and commit_to > 0
  55.        """
  56.         self.env.cr.execute(query_select_current_stock_dc)
  57.         current_stock_dc = self.env.cr.dictfetchall()
  58.         _logger.info("%s --------------- current_stock_dc"%current_stock_dc)
  59.  
  60.         if current_stock_dc:
  61.  
  62.             for stock_dc in current_stock_dc:
  63.  
  64.                 default_code = stock_dc['default_code']
  65.                 available_contract = stock_dc['available_contract']
  66.                 commit_to = stock_dc['commit_to']
  67.                 branch = stock_dc['branch']
  68.  
  69.                 _logger.info("%s --------------- default_code"%default_code)
  70.                 _logger.info("%s --------------- available_contract"%available_contract)
  71.                 _logger.info("%s --------------- commit_to"%commit_to)
  72.                 _logger.info("%s --------------- branch"%branch)
  73.  
  74.                 if branch == 'JKT':
  75.  
  76.                     query_select_commit_to = """
  77.                        select ctob.id as to_id, jakarta as qty_jkt from commited_transfer_order_branch ctob
  78.                        left join product_product pp on ctob.product_id = pp.id
  79.                        where pp.default_code = %(default_code)s and jakarta > 0 and status = 'confirmed'
  80.                        order by jakarta desc
  81.                    """
  82.                     self.env.cr.execute(query_select_commit_to,{
  83.                         'default_code' : default_code
  84.                     })
  85.                     commited_to = self.env.cr.fetchone()
  86.                
  87.                 elif branch == 'SBY':
  88.                     query_select_commit_to = """
  89.                        select ctob.id as to_id, jakarta as qty_jkt from commited_transfer_order_branch ctob
  90.                        left join product_product pp on ctob.product_id = pp.id
  91.                        where pp.default_code = %(default_code)s and surabaya > 0 and status = 'confirmed'
  92.                        order by surabaya desc
  93.                    """
  94.                     self.env.cr.execute(query_select_commit_to,{
  95.                         'default_code' : default_code
  96.                     })
  97.                     commited_to = self.env.cr.fetchone()
  98.                    
  99.                 commited_to_branch = self.env['commited.transfer.order.branch'].sudo().search([('id','=',commited_to)],limit=1)
  100.                 _logger.info("%s --------------- commited_to_branch"%commited_to_branch)
  101.  
  102.                 commited_to_branch.sudo().unlink()
  103.  
  104.  
  105.  
  106.  
  107.  
  108. #
  109.     def init(self):
  110.         pnj_db = self.env['integration.external.db'].sudo().search([('server', '=', 'pnj_replication')],
  111.                                                                    limit=1)
  112.         print(pnj_db)
  113.         if not pnj_db:
  114.             raise ValidationError(
  115.                 "Server Database Replication PNJ Belum di setting, silahkan di setting external DB nya terlebih dahulu!")
  116.         sql_pnj = """
  117.                select
  118.                     pp.default_code as product,
  119.                     rb.code as branch,
  120.                     coalesce(sum(sq.quantity),0) - coalesce(sum(sq.reserved_quantity),0) as physical
  121.                 from stock_quant sq
  122.                 left join stock_location sl on sq.location_id = sl.id
  123.                inner join product_product pp on sq.product_id = pp.id
  124.                inner join product_template pt on pp.product_tmpl_id = pt.id
  125.                inner join attribute_product_category apc on pt.attribute_categ_id = apc.id
  126.                inner join res_branch rb  on sl.branch_id = rb.id
  127.                where
  128.                    sl.active = true
  129.                    and sl.usage = $$internal$$
  130.                    and pp.default_code  like $$P%$$
  131.               group by 1,2
  132.        """
  133.  
  134.         pnj_db = self.env['integration.external.db'].sudo().search([('server', '=', 'pnj_replication')],
  135.                                                                    limit=1)
  136.         # print(pnj_db)
  137.         # if not pnj_db:
  138.         #     raise ValidationError(
  139.         #         "Server Database Replication PNJ Belum di setting, silahkan di setting external DB nya terlebih dahulu!")
  140.         sql_pnj = """
  141.                        select
  142.                             pp.default_code as product,
  143.                             rb.code as branch,
  144.                             coalesce(sum(sq.quantity),0) - coalesce(sum(sq.reserved_quantity),0) as physical
  145.                         from stock_quant sq
  146.                         left join stock_location sl on sq.location_id = sl.id
  147.                        inner join product_product pp on sq.product_id = pp.id
  148.                        inner join product_template pt on pp.product_tmpl_id = pt.id
  149.                        inner join attribute_product_category apc on pt.attribute_categ_id = apc.id
  150.                        inner join res_branch rb  on sl.branch_id = rb.id
  151.                        where
  152.                            sl.active = true
  153.                            and sl.usage = $$internal$$
  154.                            and pp.default_code  like $$P%$$
  155.                       group by 1,2
  156.                """
  157.         com_db = self.env['integration.external.db'].sudo().search([('server', '=', 'repl_community')],
  158.                                                                    limit=1)
  159.         # if not com_db:
  160.         #     raise ValidationError(
  161.         #         "Server Database Replication Community Belum di setting, silahkan di setting external DB nya terlebih dahulu!")
  162.  
  163.         sql_com = """
  164.            select
  165.                     branch,
  166.                     product,
  167.                     sum(so_draft) as so_draft,
  168.                     sum(so_waiting) as so_waiting,
  169.                     sum(so_staging_mnf) as so_staging_mnf,
  170.                    sum(psr_draft) as psr_draft,
  171.                     sum(psr) as psr
  172.                 from (
  173.                     select
  174.                     branch,
  175.                     product,
  176.                     sum(so_draft) as so_draft,
  177.                     sum(so_waiting) as so_waiting,
  178.                     sum(so_staging_mnf) as so_staging_mnf,
  179.                     sum(psr_draft) as psr_draft,
  180.                     sum(psr) as psr
  181.                     from (
  182.                         select
  183.                             rb.code as branch,
  184.                             pp.default_code as product,
  185.                             SUM(CASE WHEN so.state = $$draft$$ THEN sol.product_uom_qty ELSE 0 END) AS so_draft,
  186.                             SUM(CASE WHEN so.state = $$waiting_confirmation$$ THEN sol.product_uom_qty ELSE 0 END) AS so_waiting,
  187.                             0 as so_staging_mnf,
  188.                            0 as psr_draft,
  189.                             0 as psr
  190.                         from sale_order_line sol
  191.                         left join sale_order so on sol.order_id = so.id
  192.                         left join res_branch rb on so.branch_id = rb.id
  193.                         left join product_product pp on sol.product_id = pp.id
  194.                         group by 1,2
  195.                     ) a
  196.                     group by 1,2
  197.                     union all(
  198.                         -- SO Staging MNF
  199.                         select
  200.                             rb.code as branch,
  201.                             l.product_code as product,
  202.                             0 as so_draft,
  203.                             0 as so_waiting,
  204.                             sum(l.product_qty) as so_staging_mnf,
  205.                             0 as psr_draft,
  206.                             0 as psr
  207.                         from so_staging_crmmnf_line l
  208.                         left join so_staging_crmmnf hd on l.so_staging_id = hd.id
  209.                         left join res_branch rb on hd.branch_id = rb.id
  210.                         where hd.state in ($$confirm$$,$$waiting_ppic$$)
  211.                         group by 1,2
  212.                     )
  213.                     union all(
  214.                         -- PSR
  215.                         select
  216.                             rb.code as branch,
  217.                             pp.default_code as product,
  218.                             0 as so_draft,
  219.                             0 as so_waiting,
  220.                             0 as so_staging_mnf,
  221.                             SUM(CASE WHEN psr.state = $$draft$$ THEN psrl.request_qty ELSE 0 END) as psr_draft,
  222.                             SUM(CASE WHEN psr.state in ($$waiting_sm$$,$$waiting_gm_sales$$) THEN psrl.request_qty ELSE 0 END) as psr_draft
  223.                         from product_sample_request_line psrl
  224.                         left join product_sample_request psr on psrl.product_sample_request_id = psr.id
  225.                         left join res_branch rb on psr.branch_id = rb.id
  226.                         left join product_product pp on psrl.product_id = pp.id
  227.                         where psr.state in ($$draft$$,$$waiting_sm$$,$$waiting_gm_sales$$)
  228.                         group by 1,2
  229.                     )
  230.                 ) community
  231.                 group by 1,2
  232.        """
  233.  
  234.  
  235.         sql = """
  236.                 select
  237.                row_number() OVER() AS id,
  238.                *
  239.                from (
  240.                    select
  241.                     category_id,
  242.                     category_name,
  243.                     product,
  244.                     branch,
  245.                     coalesce(sum(physical),0) as physical,
  246.                     coalesce(sum(so_draft),0) as so_draft,
  247.                     coalesce(sum(so_confirm),0) as so_confirm,
  248.                     coalesce(sum(so_waiting),0) as so_waiting,
  249.                     coalesce(sum(so_staging_mnf),0) as so_staging_mnf,
  250.                     coalesce(max(commit_to_draft),0) as commit_to_draft,
  251.                     coalesce(sum(commit_to),0) as commit_to,
  252.                     coalesce(sum(to_satu_branch),0) as to_satu_branch,
  253.                     coalesce(sum(to_antar_branch),0) as to_antar_branch,
  254.                     coalesce(sum(mo),0) as mo,
  255.                     coalesce(sum(mo_draft),0) as mo_draft,
  256.                    coalesce(sum(psr_draft),0) as psr_draft,
  257.                     coalesce(sum(psr),0) as psr,
  258.                     coalesce(sum(psr_confirm),0) as psr_confirm,
  259.                     coalesce(sum(dynamic_reserve),0) as dynamic_reserve,
  260.                     (
  261.                         coalesce(sum(physical),0)
  262.                         - coalesce(sum(so_confirm),0)
  263.                         - coalesce(sum(so_waiting),0)
  264.                         - coalesce(sum(so_staging_mnf),0)
  265.                         - coalesce(sum(dynamic_reserve),0)
  266.                         - coalesce(sum(commit_to),0)
  267.                         + coalesce(sum(to_satu_branch),0)
  268.                         - coalesce(sum(to_antar_branch),0)
  269.                         - coalesce(sum(mo),0)
  270.                        - coalesce(sum(psr),0)
  271.                         - coalesce(sum(psr_confirm),0)
  272.                     ) as available_spot,
  273.                     (
  274.                         coalesce(sum(physical),0)  
  275.                         - coalesce(sum(so_confirm),0)
  276.                         - coalesce(sum(so_draft),0)
  277.                         - coalesce(sum(so_waiting),0)
  278.                         - coalesce(sum(so_staging_mnf),0)
  279.                         - coalesce(sum(commit_to),0)
  280.                         - coalesce(sum(commit_to_draft),0)
  281.                         + coalesce(sum(to_satu_branch),0)
  282.                         - coalesce(sum(to_antar_branch),0)
  283.                         - coalesce(sum(mo),0)
  284.                         - coalesce(sum(mo_draft),0)
  285.                         - coalesce(sum(dynamic_reserve),0)
  286.                        - coalesce(sum(psr),0)
  287.                         - coalesce(sum(psr_confirm),0)
  288.                        - coalesce(sum(psr_draft),0)
  289.                     ) as available_spot_submit,
  290.                     (
  291.                         coalesce(sum(physical),0)
  292.                         - coalesce(sum(so_confirm),0)
  293.                         - coalesce(sum(so_waiting),0)
  294.                         - coalesce(sum(so_staging_mnf),0)
  295.                         - coalesce(sum(commit_to),0)
  296.                         - coalesce(sum(mo),0)
  297.                         + coalesce(sum(to_satu_branch),0)
  298.                         - coalesce(sum(to_antar_branch),0)
  299.                        - coalesce(sum(psr),0)
  300.                         - coalesce(sum(psr_confirm),0)
  301.                     ) as available_contract,
  302.                     (
  303.                         coalesce(sum(physical),0)  
  304.                         - coalesce(sum(so_confirm),0)
  305.                         - coalesce(sum(so_draft),0)
  306.                         - coalesce(sum(so_waiting),0)
  307.                         - coalesce(sum(commit_to),0)
  308.                         - coalesce(sum(commit_to_draft),0)
  309.                         - coalesce(sum(so_staging_mnf),0)
  310.                         + coalesce(sum(to_satu_branch),0)
  311.                         - coalesce(sum(to_antar_branch),0)
  312.                         - coalesce(sum(mo),0)
  313.                         - coalesce(sum(mo_draft),0)
  314.                        - coalesce(sum(psr),0)
  315.                         - coalesce(sum(psr_confirm),0)
  316.                        - coalesce(sum(psr_draft),0)
  317.                     ) as available_contract_submit
  318.                  from (
  319.                                select  
  320.                                apc.id as category_id,
  321.                                apc.name as category_name,
  322.                                pp.default_code as product,
  323.                                rb.code as branch,
  324.                                coalesce(sum(sq.quantity),0) as physical,
  325.                                coalesce(max(so_draft.so_draft),0) so_draft,
  326.                                coalesce(max(so_confirm.so_confirm),0) as so_confirm,
  327.                                coalesce(max(so_draft.so_waiting),0) as so_waiting,
  328.                                coalesce(max(so_draft.so_staging_mnf),0) as so_staging_mnf,
  329.                                MAX(CASE WHEN rb.code = $$JKT$$ THEN commit_to_draft.jkt ELSE commit_to_draft.sby END) AS commit_to_draft,
  330.                                MAX(CASE WHEN rb.code = $$JKT$$ THEN commit_to.jkt ELSE commit_to.sby END) AS commit_to,
  331.                                max(to_satu_branch.to_satu_branch) as to_satu_branch,
  332.                                max(to_antar_branch.to_antar_branch) as to_antar_branch,
  333.                                coalesce(max(mo.mo),0) as mo,
  334.                                coalesce(max(mo_draft.mo_draft),0) as mo_draft,
  335.                                coalesce(max(so_draft.psr_draft),0) as psr_draft,
  336.                                coalesce(max(so_draft.psr),0) as psr,
  337.                                coalesce(max(psr_ent.psr),0) as psr_confirm,
  338.                                max(dynamic.dynamic) as dynamic_reserve
  339.                            from stock_quant sq
  340.                            left join stock_location sl on sq.location_id = sl.id
  341.                            inner join product_product pp on sq.product_id = pp.id
  342.                            inner join product_template pt on pp.product_tmpl_id = pt.id
  343.                            inner join attribute_product_category apc on pt.attribute_categ_id = apc.id
  344.                            inner join res_branch rb  on sl.branch_id = rb.id
  345.                            inner join status_location statloc on statloc.id = sl.status_location_id
  346.                            full join dblink('host=%s dbname=%s user=%s password=%s', '%s') so_draft (
  347.                                branch VARCHAR,
  348.                                product VARCHAR,
  349.                                so_draft FLOAT,
  350.                                so_waiting FLOAT,
  351.                                so_staging_mnf FLOAT,
  352.                                psr_draft FLOAT,
  353.                                psr FLOAT
  354.                            ) on pp.default_code = so_draft.product and rb.code = so_draft.branch
  355.                            full join (
  356.                                select
  357.                                    rb.code as branch,
  358.                                    pp.default_code as product,
  359.                                    SUM(CASE WHEN so.status_so  in ('confirmed','assigned_to_pick','on_picking') THEN sol.product_uom_qty ELSE 0 END) AS so_confirm
  360.                                from sale_order_line sol
  361.                                left join sale_order so on sol.order_id = so.id
  362.                                left join res_branch rb on so.branch_id = rb.id
  363.                                left join product_product pp on sol.product_id = pp.id
  364.                                group by 1,2
  365.                            ) so_confirm on pp.default_code = so_confirm.product and rb.code = so_confirm.branch
  366.                            full join (
  367.                                select
  368.                                    pp.default_code as product,
  369.                                    sum(cto.jakarta) as jkt,
  370.                                    sum(cto.surabaya) as sby
  371.                                from commited_transfer_order_branch cto
  372.                                left join product_product pp on cto.product_id = pp.id
  373.                                where cto.status = 'draft'
  374.                                group by product
  375.                            ) commit_to_draft on pp.default_code = commit_to_draft.product
  376.                            left join (
  377.                                select
  378.                                    rb.code as branch,
  379.                                    pp.default_code as product,
  380.                                    SUM(psrl.request_qty) as psr
  381.                                from product_sample_request_line psrl
  382.                                left join product_sample_request psr on psrl.product_sample_request_id = psr.id
  383.                                left join res_branch rb on psr.branch_id = rb.id
  384.                                left join product_product pp on psrl.product_id = pp.id
  385.                                where psr.state in ($$confirm$$,$$assigned_to_pick$$,$$on_picking$$)
  386.                                group by 1,2
  387.                            ) psr_ent on pp.default_code = psr_ent.product and rb.code = psr_ent.branch
  388.                            full join (
  389.                                select
  390.                                    pp.default_code as product,
  391.                                    sum(cto.jakarta) as jkt,
  392.                                    sum(cto.surabaya) as sby
  393.                                from commited_transfer_order_branch cto
  394.                                left join product_product pp on cto.product_id = pp.id
  395.                                where cto.status = 'confirmed'
  396.                                group by product
  397.                            ) commit_to on pp.default_code = commit_to.product
  398.                            full join (
  399.                                 select
  400.                                    rb.code as branch,
  401.                                    pp.default_code as product,
  402.                                    SUM(CASE WHEN to2.status in ($$assigned$$,$$on_picking$$) THEN mtol.confirm_qty  ELSE 0 END) AS confirm_qty,
  403.                                    SUM(CASE WHEN to2.status in ($$done_picking$$,$$on_rack_prepare$$) THEN mtol.picked_qty ELSE 0 END) AS picked_qty,
  404.                                    SUM(CASE WHEN to2.status in ($$shipped$$,$$received$$) THEN mtol.shipped_qty ELSE 0 END) AS shipped_qty,
  405.                                    SUM(CASE WHEN to2.status in ($$done_picking$$,$$on_rack_prepare$$) THEN mtol.picked_qty ELSE 0 END) +
  406.                                    SUM(CASE WHEN to2.status in ($$shipped$$,$$received$$) THEN mtol.shipped_qty ELSE 0 END) as to_satu_branch
  407.                                from merge_transfer_order_line mtol
  408.                                left join transfer_order to2 on mtol.transfer_order_id  = to2.id
  409.                                inner join res_branch rb on to2.source_branch_id = rb.id
  410.                                left join product_product pp on mtol.product_id = pp.id
  411.                                where to2.status not in ('draft', 'confirmed','cancel')
  412.                                and to2.satu_branch = true
  413.                                group by 1,2
  414.                            ) to_satu_branch on pp.default_code = to_satu_branch.product and rb.code = to_satu_branch.branch
  415.                            full join (
  416.                                 select
  417.                                    rb.code as branch,
  418.                                    pp.default_code as product,
  419.                                    SUM(CASE WHEN to2.status in ($$draft$$,$$assigned$$,$$on_picking$$,$$confirmed$$) and coalesce(rb2.virtual_branch, false) != true THEN mtol.confirm_qty  ELSE 0 END) AS confirm_qty,
  420.                                    SUM(CASE WHEN to2.status in ($$done_picking$$,$$on_rack_prepare$$) and coalesce(rb2.virtual_branch, false) != true THEN mtol.picked_qty ELSE 0 END) AS picked_qty,
  421.                                    SUM(CASE WHEN to2.status in ($$shipped$$,$$received$$) and coalesce(rb2.virtual_branch, false) != true THEN mtol.shipped_qty ELSE 0 END) AS shipped_qty,
  422.                                    SUM(CASE WHEN to2.status in ($$draft$$,$$assigned$$,$$on_picking$$,$$confirmed$$) and coalesce(rb2.virtual_branch, false) != true THEN mtol.confirm_qty  ELSE 0 END) as to_antar_branch
  423.                                from merge_transfer_order_line mtol
  424.                                left join transfer_order to2 on mtol.transfer_order_id  = to2.id
  425.                                inner join res_branch rb on to2.source_branch_id = rb.id
  426.                                left join res_branch rb2 on to2.destination_branch_id = rb2.id
  427.                                left join product_product pp on mtol.product_id = pp.id
  428.                                where to2.status in ('draft','confirmed','assigned','on_picking')
  429.                                and to2.antar_branch = true
  430.                                group by 1,2
  431.                            ) to_antar_branch on pp.default_code = to_antar_branch.product and rb.code = to_antar_branch.branch
  432.                            left join (
  433.                                select product,source_branch as branch,sum(stock_allocation) as dynamic from  demand_dc_contract_allocation bca group by 1,2
  434.                            ) dynamic on pp.default_code = dynamic.product and rb.code = dynamic.branch
  435.                            left join (
  436.                                select
  437.                                    rb.code as branch,
  438.                                    pp.default_code as product,
  439.                                    GREATEST(0, sum(amc.product_uom_qty) - sum(amc.comsume_qty)) as mo
  440.                                from abu_mrp_consumed amc
  441.                                left join abu_mrp_production amp on amc.production_id = amp.id
  442.                                inner join res_branch rb on amp.branch_id  = rb.id
  443.                                inner join product_product pp on amc.product_id = pp.id
  444.                                where amp.state in ('confirmed','assigned_pick','done_pick')
  445.                                group by 1,2
  446.                            ) mo on pp.default_code = mo.product and rb.code = mo.branch
  447.                            left join (
  448.                                select
  449.                                    rb.code as branch,
  450.                                    pp.default_code as product,
  451.                                    sum(amc.product_uom_qty) as mo_draft
  452.                                from abu_mrp_consumed amc
  453.                                left join abu_mrp_production amp on amc.production_id = amp.id
  454.                                inner join res_branch rb on amp.branch_id  = rb.id
  455.                                inner join product_product pp on amc.product_id = pp.id
  456.                                where amp.state = 'draft'
  457.                                group by 1,2
  458.                            ) mo_draft on pp.default_code = mo_draft.product and rb.code = mo_draft.branch
  459.                            where
  460.                                sl.active = true
  461.                                and sl.usage = $$internal$$
  462.                                and statloc.type = $$available$$
  463.                                and pt.item_type = 'commercial'
  464.                                and sq.quantity > 0
  465.                                and sl.id in (SELECT
  466.                                    sl.id
  467.                                   FROM stock_location sl
  468.                                   left join stock_location sl2 on sl.location_id = sl2.id
  469.                                   where sl2.name = 'Stock')
  470.                           group by 1,2,3,4
  471.                 ) a
  472.                 where branch in ('JKT','SBY')
  473.                 group by 1,2,3,4
  474. )a
  475.        """ % (com_db.host, com_db.dbname, com_db.user, com_db.password, sql_com, )
  476.         # print("""
  477.         #     CREATE EXTENSION IF NOT EXISTS dblink;
  478.         #     CREATE OR REPLACE VIEW %s AS (%s) ;
  479.         #     """ % (self._table, sql))
  480.  
  481.         tools.drop_view_if_exists(self._cr, self._table)
  482.         self._cr.execute("""
  483.            CREATE EXTENSION IF NOT EXISTS dblink;
  484.            CREATE OR REPLACE VIEW %s AS (%s) ;
  485.            """ % (self._table, sql)
  486.                          )
Advertisement
Add Comment
Please, Sign In to add comment