How to get a different sequence based on field

I have the custom field:

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:

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.

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.

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