Beispiel #1
0
    def copy(cls, locations, default=None):
        if default is None:
            default = {}

        default['left'] = 0
        default['right'] = 0

        res = []
        for location in locations:
            if location.type == 'warehouse':

                wh_default = default.copy()
                wh_default['type'] = 'view'
                wh_default['input_location'] = None
                wh_default['output_location'] = None
                wh_default['storage_location'] = None
                wh_default['childs'] = None

                new_location, = super(Location, cls).copy([location],
                                                          default=wh_default)

                with Transaction().set_context(
                        cp_warehouse_locations={
                            'input_location': location.input_location.id,
                            'output_location': location.output_location.id,
                            'storage_location': location.storage_location.id,
                        },
                        cp_warehouse_id=new_location.id):
                    cls.copy(location.childs,
                             default={'parent': new_location.id})
                cls.write([new_location], {
                    'type': 'warehouse',
                })
            else:
                new_location, = super(Location, cls).copy([location],
                                                          default=default)
                warehouse_locations = Transaction().context.get(
                    'cp_warehouse_locations') or {}
                if location.id in warehouse_locations.values():
                    cp_warehouse = cls(
                        Transaction().context['cp_warehouse_id'])
                    for field, loc_id in warehouse_locations.iteritems():
                        if loc_id == location.id:
                            cls.write([cp_warehouse], {
                                field: new_location.id,
                            })

            res.append(new_location)
        return res
    def copy(cls, locations, default=None):
        if default is None:
            default = {}

        default['left'] = 0
        default['right'] = 0

        res = []
        for location in locations:
            if location.type == 'warehouse':

                wh_default = default.copy()
                wh_default['type'] = 'view'
                wh_default['input_location'] = None
                wh_default['output_location'] = None
                wh_default['storage_location'] = None
                wh_default['childs'] = None

                new_location, = super(Location, cls).copy([location],
                    default=wh_default)

                with Transaction().set_context(
                        cp_warehouse_locations={
                            'input_location': location.input_location.id,
                            'output_location': location.output_location.id,
                            'storage_location': location.storage_location.id,
                            },
                        cp_warehouse_id=new_location.id):
                    cls.copy(location.childs,
                        default={'parent': new_location.id})
                cls.write([new_location], {
                        'type': 'warehouse',
                        })
            else:
                new_location, = super(Location, cls).copy([location],
                    default=default)
                warehouse_locations = Transaction().context.get(
                    'cp_warehouse_locations') or {}
                if location.id in warehouse_locations.values():
                    cp_warehouse = cls(
                        Transaction().context['cp_warehouse_id'])
                    for field, loc_id in warehouse_locations.iteritems():
                        if loc_id == location.id:
                            cls.write([cp_warehouse], {
                                    field: new_location.id,
                                    })

            res.append(new_location)
        return res
Beispiel #3
0
    def copy(cls, locations, default=None):
        if default is None:
            default = {}

        default["left"] = 0
        default["right"] = 0

        res = []
        for location in locations:
            if location.type == "warehouse":

                wh_default = default.copy()
                wh_default["type"] = "view"
                wh_default["input_location"] = None
                wh_default["output_location"] = None
                wh_default["storage_location"] = None
                wh_default["childs"] = None

                new_location, = super(Location, cls).copy([location], default=wh_default)

                with Transaction().set_context(
                    cp_warehouse_locations={
                        "input_location": location.input_location.id,
                        "output_location": location.output_location.id,
                        "storage_location": location.storage_location.id,
                    },
                    cp_warehouse_id=new_location.id,
                ):
                    cls.copy(location.childs, default={"parent": new_location.id})
                cls.write([new_location], {"type": "warehouse"})
            else:
                new_location, = super(Location, cls).copy([location], default=default)
                warehouse_locations = Transaction().context.get("cp_warehouse_locations") or {}
                if location.id in warehouse_locations.values():
                    cp_warehouse = cls(Transaction().context["cp_warehouse_id"])
                    for field, loc_id in warehouse_locations.iteritems():
                        if loc_id == location.id:
                            cls.write([cp_warehouse], {field: new_location.id})

            res.append(new_location)
        return res