Error on product.save() : A value is required for field "Product Template" in "Product Variant"

I am trying to import Product/Variant data using proteus.

I am setting the following data:
product.code
product.attributes
product.description
template.id

When I call
product.save()

I get this error:

trytond.model.modelstorage.RequiredValidationError:
A value is required for field “Product Template” in “Product Variant”. -

and I can’t figure out how to set this value.

You should use the product name as template field.

The server will take care of searching for the template and set the value to it.

I set product.name to an entry already created using the client interface but I am still getting the same error:
trytond.model.modelstorage.RequiredValidationError: A value is required for field “Product Template” in "Product Variant"

There is also an error:
psycopg2.IntegrityError: null value in column “template” violates not-null constraint

I guess that is from the database.

Oups, I tought you where using the import/export feature but I realized that you are using proteus.

In proteus you should first create a template record and then create the variants related to it.

You can use the following snipped as reference:

Template = Model.get('product.tempate')
template = Template()
template.name = 'T-Shirt'
# set all the required fields ie:
template.unit = unit
# A product is automatically created as per default value
product, = template.products
product.code = '1234-W'
# Set whatever attributes you need
product.color = 'WHITE'
for color in colors:
    product = template.products.new()
    product.code = '1234-C'
    product.color = color
# Save template and all the related products
template.save()

Hope it helps

template.unit doesn’t seem to exist.
I see there is a template.default_uom
but I cannot set it to a value.

Of course that was just a sample. The field is name default_uom and you just set a record from the ‘product.uom’ table.

There are lot of working examples in the tests scearios of the modules. Here you have the invoice one.

default_uom is a many to one. Check out this code example to view how to set the unit to template.

Thank you all for trying to help but using proteus requires a much deeper understanding of Tryton than I have. Unfortunately the client interface import is broken for Attributes which is what led me to try proteus.

Since there is no other way forward, I inserted the Attributes directly into the database.