# How to get a different sequence based on field

**URL:** https://discuss.tryton.org/t/how-to-get-a-different-sequence-based-on-field/4935
**Category:** Developer
**Created:** [January 20, 2022, 3:49pm UTC](https://discuss.tryton.org/t/how-to-get-a-different-sequence-based-on-field/4935 "2022-01-20T15:49:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![acaubet](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/acaubet/32/1493_2.png) [@acaubet](https://discuss.tryton.org/u/acaubet)
#### Post date: [January 20, 2022, 3:49pm UTC](https://discuss.tryton.org/t/how-to-get-a-different-sequence-based-on-field/4935/1 "2022-01-20T15:49:23Z")

</div>

I have the custom field:

```auto
class Sale(metaclass=PoolMeta):
    custom_field = fields.Many2One('custom.model', "CUSTOM FIELD")

    def get_production(self):
        production = super().get_production()
        production.custom_field = self.custom_field
        return production

```

On creating the shipment I want the shipment to use a sequence based on that field, somethink like this:

```auto
class Production(metaclass=PoolMeta):
    __name__ = 'production'

    custom_field = fields.Many2One('custom.model', "CUSTOM FIELD")

    @classmethod
    def create(cls, vlist):
        pool = Pool()
        Config = pool.get('production.configuration')
        vlist = [x.copy() for x in vlist]
        config = Config(1)
        default_company = cls.default_company()
        for values in vlist:
            if values.get('number') is None:
                values['number'] = config.get_multivalue(
                    'production_sequence',
                    custom_field=values.get('custom_field'),
                    company=values.get('company', default_company)).get()
        productions = super().create(vlist)
        return productions

```

But I don’t know how to extend sequence or config to allow this.  
Also If there are other simple/clean solutions feel free to suggest.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [January 20, 2022, 4:35pm UTC](https://discuss.tryton.org/t/how-to-get-a-different-sequence-based-on-field/4935/2 "2022-01-20T16:35:05Z")

</div>

> [@acaubet](#):
>
> But I don’t know how to extend sequence or config to allow this.

You should add your custom field to the sequence multivalue model and define a diferent sequence record for each custom\_field value. Then the `get_multivalue` will pick the right values with your current code.

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [February 19, 2022, 4:35pm UTC](https://discuss.tryton.org/t/how-to-get-a-different-sequence-based-on-field/4935/3 "2022-02-19T16:35:30Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
