Getting Party Sequence the right way

Hi,

If using Company module to create an employee, our HR find it very confusing that he/she required to create Party first, and not mention HR need extra data to be collected for each employee.
So I created a module specific to ease their life. But I am stuck with creation Party here:

    @classmethod
    def create(cls, record):
        pool = Pool()
        Party = pool.get('party.party')

        party_values = [{
            'name': record[0].get('name', ''),
            'active': True,
            'code': #-- should come from party sequence --,
            'create_uid': 1,
            'write_uid': 1,
        }]
        new_party = Party.create(party_values)

I need to be able to pull party sequence for filling the right code for new Party record.
Can anybody help?

Bromo

You can omit to set any value for the code, if a sequence is configured for the party, the ORM will use it.

Also it is probably easier to use an instance instead of Party.create like:

party = Party(name=record[0].get('name', ''))
party.save()

And in 7.6 series, you should use the preprocess_values hook instead of extending ModelStorage.create.

2 Likes