コード例 #1
0
    def action_done(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            inven_api = api_object.execute_kw(api.api_database, api_uid,
                                              api.api_password,
                                              'stock.inventory', 'search',
                                              [[('name', '=', self.name),
                                                ('state', '=', self.state)]])

            if self.line_ids:
                for line in self.line_ids:
                    line_vals = {
                        'product_id': line.product_id.id,
                        'product_uom_id': line.product_uom_id.id,
                        'location_id': line.location_id.id,
                        'product_qty': line.product_qty,
                        'inventory_id': inven_api[0]
                    }
                    line_api = api_object.execute_kw(api.api_database, api_uid,
                                                     api.api_password,
                                                     'stock.inventory.line',
                                                     'create', [line_vals])

            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'stock.inventory', 'action_done',
                                  [inven_api])

        return super(SakinahInventory, self).action_done()
コード例 #2
0
    def create(self, vals):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            if not vals.get('origin') and vals.get('parent_batch'):
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password, 'stock.picking',
                                      'create', [vals])

        # TDE FIXME: clean that brol
        defaults = self.default_get(['name', 'picking_type_id'])
        if vals.get('name', '/') == '/' and defaults.get(
                'name', '/') == '/' and vals.get(
                    'picking_type_id', defaults.get('picking_type_id')):
            vals['name'] = self.env['stock.picking.type'].browse(
                vals.get(
                    'picking_type_id',
                    defaults.get('picking_type_id'))).sequence_id.next_by_id()

        # TDE FIXME: what ?
        # As the on_change in one2many list is WIP, we will overwrite the locations on the stock moves here
        # As it is a create the format will be a list of (0, 0, dict)
        if vals.get('move_lines') and vals.get('location_id') and vals.get(
                'location_dest_id'):
            for move in vals['move_lines']:
                if len(move) == 3:
                    move[2]['location_id'] = vals['location_id']
                    move[2]['location_dest_id'] = vals['location_dest_id']

        return super(Sakinah_Picking, self).create(vals)
コード例 #3
0
    def button_done(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        for line in self:
            count = 0
            finished = 0
            for subline in line.stock_picking:
                count += 1
                #if subline.state == 'done':
                if subline.state in ['done', 'cancel']:
                    finished += 1
            if count == finished:
                self.write({'state': 'done'})
            else:
                raise UserError(_('Tidak dapat menyelesaikan transaksi'\
                    ' jika masih ada transfer yang belum berstatus (done)'))
        if api_uid and api_uid != self.env.uid:
            wh_batch_api = api_object.execute_kw(api.api_database, api_uid,
                                                 api.api_password,
                                                 'sakinah.warehouse.batch',
                                                 'search',
                                                 [[('name', '=', self.name)]])
            if wh_batch_api:
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password,
                                      'sakinah.warehouse.batch', 'button_done',
                                      [wh_batch_api])

        return True
コード例 #4
0
    def action_assign(self):
        """ Check availability of picking moves.
        This has the effect of changing the state and reserve quants on available moves, and may
        also impact the state of the picking as it is computed based on move's states.
        @return: True
        """
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        self.filtered(
            lambda picking: picking.state == 'draft').action_confirm()
        moves = self.mapped('move_lines').filtered(
            lambda move: move.state not in ('draft', 'cancel', 'done'))
        if not moves:
            raise UserError(_('Nothing to check the availability for.'))
        moves.action_assign()

        if api_uid and api_uid != self.env.uid:
            pick_api = api_object.execute_kw(api.api_database, api_uid,
                                             api.api_password, 'stock.picking',
                                             'search',
                                             [[('name', '=', self.name)]])
            if pick_api:
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password, 'stock.picking',
                                      'action_assign', [pick_api])

        return True
コード例 #5
0
    def create(self, vals):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        new_vals = {
            'name': vals['name'],
            'product_id': vals['product_id'],
            'product_qty': vals['product_qty'],
            'warehouse_id': vals['warehouse_id'],
            'product_uom': vals['product_uom'],
            'location_id': vals['location_id'],
            'route_ids': vals['route_ids']
        }

        if api_uid and api_uid != self.env.uid:
            procurement_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password,
                'procurement.order', 'search', [[('name', '=', self.name)]])
            if not procurement_api and vals['name'] != 'Transit':
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password, 'procurement.order',
                                      'create', [new_vals])

        return super(ProcurementOrder, self).create(vals)
コード例 #6
0
    def process(self):

        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            pick_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password, 'stock.picking',
                'search', [[('name', '=', self.pick_id.name)]])
            if pick_api:
                ime_api = api_object.execute_kw(api.api_database, api_uid,
                                                api.api_password,
                                                'stock.immediate.transfer',
                                                'create',
                                                [{
                                                    'pick_id': pick_api[0]
                                                }])
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password,
                                      'stock.immediate.transfer', 'process',
                                      [ime_api])

        self.ensure_one()
        # If still in draft => confirm and assign
        if self.pick_id.state == 'draft':
            self.pick_id.action_confirm()
            if self.pick_id.state != 'assigned':
                self.pick_id.action_assign()
                if self.pick_id.state != 'assigned':
                    raise UserError(
                        _("Could not reserve all requested products. Please use the \'Mark as Todo\' button to handle the reservation manually."
                          ))
        for pack in self.pick_id.pack_operation_ids:
            if pack.product_qty > 0:
                pack.write({'qty_done': pack.product_qty})
            else:
                pack.unlink()

            quants = self.env['stock.quant'].search([
                ('location_id', '=', self.pick_id.location_id.id),
                ('product_id', '=', pack.product_id.id)
            ])
            quants_qty = 0
            for quant in quants:
                quants_qty += quant.qty

            if pack.qty_done > quants_qty and self.pick_id.location_id.usage == 'internal':
                raise UserError(_('Tidak bisa memproses barang jika jumlah barang yang diterima melebihi barang yg tersedia.\n'\
                        'jumlah %s yang tersedia : %s' % (pack.product_id.name, quants_qty)))

            print('####################################################')
            if self.pick_id.purchase_id.id and self.pick_id.purchase_id.state == 'purchase':
                print('####################################################')
                self.pick_id.purchase_id.write({'state': 'shipped'})

        self.pick_id.do_transfer()

        return True
コード例 #7
0
    def create(self, vals):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'product.template', 'create', [vals])

        return super(ProductTemplate, self).create(vals)
コード例 #8
0
    def create(self, vals):
        ''' Store the initial standard price in order to be able to retrieve the cost of a product template for a given date'''
        # TDE FIXME: context brol
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'stock.inventory', 'create', [vals])

        return super(SakinahInventory, self).create(vals)
コード例 #9
0
    def run(self, autocommit=False):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            procurement_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password,
                'procurement.order', 'search', [[('name', '=', self.name)]])
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'procurement.order', 'run',
                                  [procurement_api])

        return super(ProcurementOrder, self).run(autocommit=autocommit)
コード例 #10
0
    def reset_to_confirmed(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            procurement_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password,
                'procurement.order', 'search', [[('name', '=', self.name)]])
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'procurement.order', 'reset_to_confirmed',
                                  [procurement_api])

        return self.write({'state': 'confirmed'})
コード例 #11
0
    def prepare_inventory(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            inven_api = api_object.execute_kw(api.api_database, api_uid,
                                              api.api_password,
                                              'stock.inventory', 'search',
                                              [[('name', '=', self.name),
                                                ('state', '=', self.state)]])
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'stock.inventory', 'prepare_inventory',
                                  [inven_api])

        return super(SakinahInventory, self).prepare_inventory()
コード例 #12
0
    def action_cancel_draft(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            inven_api = api_object.execute_kw(api.api_database, api_uid,
                                              api.api_password,
                                              'stock.inventory', 'search',
                                              [[('name', '=', self.name),
                                                ('state', '=', self.state)]])
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'stock.inventory', 'action_cancel_draft',
                                  [inven_api])

        self.mapped('move_ids').action_cancel()
        self.write({'line_ids': [(5, )], 'state': 'draft'})

        return True
コード例 #13
0
    def cancel(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if api_uid and api_uid != self.env.uid:
            procurement_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password,
                'procurement.order', 'search',
                [[('name', '=', self.name),
                  ('create_date', '=', self.create_date),
                  ('state', '=', 'cancel')]])
            api_object.execute_kw(api.api_database, api_uid, api.api_password,
                                  'procurement.order', 'cancel',
                                  [procurement_api])

        propagated_procurements = self.filtered(
            lambda order: order.state != 'done').propagate_cancels()
        if propagated_procurements:
            propagated_procurements.cancel()
        return super(ProcurementOrder, self).cancel()
コード例 #14
0
    def create(self, vals):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        if vals.get('name', 'New') == 'New':
            vals['name'] = self.env['ir.sequence'].next_by_code(
                'sakinah.wh.batch') or '/'
        print(self.env.user)
        print(self.env.uid)
        if api_uid and api_uid != self.env.uid:
            wh_batch_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password,
                'sakinah.warehouse.batch', 'search',
                [[('name', '=', vals['name'])]])
            if not wh_batch_api:
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password,
                                      'sakinah.warehouse.batch', 'create',
                                      [vals])

        return super(Sakinah_Warehouse_Batch, self).create(vals)
コード例 #15
0
    def action_cancel(self):

        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        context = self._context
        self.mapped('move_lines').action_cancel(
            context.get('do_rollback', False))
        if not self.move_lines:
            self.write({'state': 'cancel'})
        if api_uid and api_uid != self.env.uid:
            pick_api = api_object.execute_kw(api.api_database, api_uid,
                                             api.api_password, 'stock.picking',
                                             'search',
                                             [[('name', '=', self.name)]])
            if pick_api:
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password, 'stock.picking',
                                      'action_cancel', [pick_api])
        if context.get('do_rollback'):
            self.write({'state': 'draft'})
        return True
コード例 #16
0
    def process(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        self._process()

        if api_uid and api_uid != self.env.uid:
            pick_api = api_object.execute_kw(
                api.api_database, api_uid, api.api_password, 'stock.picking',
                'search', [[('name', '=', self.pick_id.name)]])
            if pick_api:
                backorder_api = api_object.execute_kw(
                    api.api_database, api_uid, api.api_password,
                    'stock.backorder.confirmation', 'create',
                    [{
                        'pick_id': pick_api[0]
                    }])
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password,
                                      'stock.backorder.confirmation',
                                      'process', [backorder_api])
        return True
コード例 #17
0
    def action_confirm(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        self.filtered(lambda picking: not picking.move_lines).write(
            {'launch_pack_operations': True})
        # TDE CLEANME: use of launch pack operation, really useful ?
        self.mapped('move_lines').filtered(
            lambda move: move.state == 'draft').action_confirm()
        self.filtered(lambda picking: picking.location_id.usage in
                      ('supplier', 'inventory', 'production')).force_assign()

        if api_uid and api_uid != self.env.uid:
            pick_api = api_object.execute_kw(api.api_database, api_uid,
                                             api.api_password, 'stock.picking',
                                             'search',
                                             [[('name', '=', self.name)]])
            if pick_api:
                api_object.execute_kw(api.api_database, api_uid,
                                      api.api_password, 'stock.picking',
                                      'action_confirm', [pick_api])

        return True
コード例 #18
0
    def do_new_transfer(self):
        api = self.env['sakinah.api'].search([('api_active', '=', True)])
        api_object = api.get_api_object()
        api_uid = api.get_uid()

        for pick in self:

            for pack in pick.pack_operation_ids:
                quants = self.env['stock.quant'].search([
                    ('location_id', '=', pick.location_id.id),
                    ('product_id', '=', pack.product_id.id)
                ])
                quants_qty = 0
                for quant in quants:
                    quants_qty += quant.qty
                if pack.qty_done > quants_qty and pick.location_id.usage == 'internal':
                    raise UserError(_('Tidak bisa memproses barang jika jumlah barang yang diterima melebihi barang yg tersedia.\n'\
                        'jumlah %s yang tersedia : %s' % (pack.product_id.name, quants_qty)))

            print(quants)

            if api_uid and api_uid != self.env.uid:
                pick_api = api_object.execute_kw(api.api_database, api_uid,
                                                 api.api_password,
                                                 'stock.picking', 'search',
                                                 [[('name', '=', self.name)]])
                pack_api = api_object.execute_kw(
                    api.api_database, api_uid, api.api_password,
                    'stock.pack.operation', 'search',
                    [[('picking_id', '=', pick_api)]])

                count = 0
                for pack in pick.pack_operation_ids:
                    if pack.qty_done and pack_api:
                        print(pack_api[count])
                        api_object.execute_kw(api.api_database, api_uid,
                                              api.api_password,
                                              'stock.pack.operation', 'write',
                                              [[pack_api[count]], {
                                                  'qty_done': pack.qty_done,
                                                  'difference': pack.difference
                                              }])

                    count += 1

            if pick.state == 'done':
                raise UserError(_('The pick is already validated'))
            pack_operations_delete = self.env['stock.pack.operation']
            if not pick.move_lines and not pick.pack_operation_ids:
                raise UserError(
                    _('Please create some Initial Demand or Mark as Todo and create some Operations. '
                      ))

            # In draft or with no pack operations edited yet, ask if we can just do everything
            if pick.state == 'draft' or all(
                [x.qty_done == 0.0 for x in pick.pack_operation_ids]):
                # If no lots when needed, raise error
                picking_type = pick.picking_type_id
                if (picking_type.use_create_lots
                        or picking_type.use_existing_lots):
                    for pack in pick.pack_operation_ids:
                        if pack.product_id and pack.product_id.tracking != 'none':
                            raise UserError(
                                _('Some products require lots/serial numbers, so you need to specify those first!'
                                  ))
                view = self.env.ref('stock.view_immediate_transfer')
                wiz = self.env['stock.immediate.transfer'].create(
                    {'pick_id': pick.id})
                # TDE FIXME: a return in a loop, what a good idea. Really.
                return {
                    'name': _('Immediate Transfer?'),
                    'type': 'ir.actions.act_window',
                    'view_type': 'form',
                    'view_mode': 'form',
                    'res_model': 'stock.immediate.transfer',
                    'views': [(view.id, 'form')],
                    'view_id': view.id,
                    'target': 'new',
                    'res_id': wiz.id,
                    'context': self.env.context,
                }
                # TDE FIXME: a return in a loop, what a good idea. Really.

            # Untuk stock picking yang pengirimannya bukan dari vendor tidak bisa validate jika penerimaan kurang dari yang seharusnya
            product = []
            count = 0
            for pack in pick.pack_operation_ids:
                if pack.child_batch.plus_sum < -pack.difference and not (
                        pick.picking_code == 1
                        or pick.picking_type_id.name == "Internal Transfers"):
                    count += 1
                    product.append(pack.product_id.name)

            product_list = ', '.join(product)
            if count > 0 and pick.parent_batch.id != False:
                raise UserError(_('Tidak bisa memproses transaksi minus untuk barang berikut ini: %s jika belum ditemukan'\
                    ' transaksi plus pada cabang lain dengan jumlah yang memadai. Silahkan tunggu beberapa saat atau hubungi kantor pusat.' % (product_list)))

            for pack in pick.pack_operation_ids:
                if pack.qty_done < pack.product_qty and pick.location_id.usage == 'supplier':
                    raise UserError(
                        _('Tidak bisa memproses barang jika jumlah barang yang diterima kurang. Harap hubungi bagian akuntansi untuk mengubah jumlah yang diterima.\n'
                          ))

                if pack.qty_done != pack.product_qty and (
                        pick.location_id.usage == 'internal'
                        and pick.parent_batch.id == False):
                    raise UserError(
                        _('Tidak bisa memproses barang jika jumlah barang yang diterima tidak sesuai. Harap hubungi pengirim untuk mengubah jumlah yang diterima.\n'
                          ))

            # Check backorder should check for other barcodes
            if pick.check_backorder():
                view = self.env.ref('stock.view_backorder_confirmation')
                wiz = self.env['stock.backorder.confirmation'].create(
                    {'pick_id': pick.id})
                # TDE FIXME: same reamrk as above actually
                return {
                    'name': _('Create Backorder?'),
                    'type': 'ir.actions.act_window',
                    'view_type': 'form',
                    'view_mode': 'form',
                    'res_model': 'stock.backorder.confirmation',
                    'views': [(view.id, 'form')],
                    'view_id': view.id,
                    'target': 'new',
                    'res_id': wiz.id,
                    'context': self.env.context,
                }

            for operation in pick.pack_operation_ids:
                product_qty = operation.product_qty
                if operation.qty_done < 0:
                    raise UserError(_('No negative quantities allowed'))
                if operation.qty_done > 0:
                    operation.write({'begining_qty': product_qty})
                    operation.write({'product_qty': operation.qty_done})
                else:
                    pack_operations_delete |= operation
            if pack_operations_delete:
                pack_operations_delete.unlink()

            if api_uid and api_uid != self.env.uid:
                pick_api = api_object.execute_kw(api.api_database, api_uid,
                                                 api.api_password,
                                                 'stock.picking', 'search',
                                                 [[('name', '=', self.name)]])
                if pick_api:
                    api_object.execute_kw(api.api_database, api_uid,
                                          api.api_password, 'stock.picking',
                                          'do_new_transfer', [pick_api])

        self.do_transfer()

        print('####################################################')
        if self.purchase_id.id and self.purchase_id.state == 'purchase':
            print('####################################################')
            purchase = self.purchase_id.write({'state': 'shipped'})

        return True