I dont think the API had canged that much, could be a data migration issue.

See below...

On 24 Oct 2014 12:27, "Luciano Rossi" <[email protected]> wrote:
>
> Hi!
>
> I develop a wizard at sale module. When the wizard finish I create some
sale lines. I develop it with tryton-3.0.
>
> I would like to migrate the module to 3.2, but with the same code gives
me an error that I don't understand why its happening.

Is this just an example or what your actual module has?

> Here is an example code. You also can find the code at pastebin (
http://pastebin.com/XDSFhLTQ )
> ```
> pool = Pool()
> t = Transaction()
> sale_line_obj = pool.get('sale.line')
> line = sale_line_obj()
>
> line.sale = t.context.get('active_id')
> line.type = 'line'
> line.quantity = 100
> line.product = 1 # First product. default_uom and sale_uom is 'unit'
> line.unit = 1 #Using 'unit'
> line.unit_price = Decimal('1')
> line.description = 'Example sale line'
> sale_line_obj.save(line)
> ```

The only thing that stands out to me is your use of hard coded "magic
number" IDs for unit if measure and product.

You cannot always count on the IDs being fixed; you should probably
reference these by name. Sometimes re installations and upgrades recreate
records and the sequence in the database just keep counting up. Not sure if
this is the case here but it is possible.

> Returns:
> *** UserError: ('UserError', (u'The value of the field "Unit" on "Sale
Line" is not valid according to its domain.', ''))
>

My theory is that the "unit" UOM record in the database was recreated with
a new ID on upgrade, and the old record deleted or marked inactive...some
tables have a field called active and the business logic requires this
field to be true.

This error means there is no valid record in the units of measure table
with ID of 1. The best solution is to specify the unit field by name not by
ID number.

> It seems that the problem is with the validate_domain() method at
modelstorage.py file. From 3.0 to 3.2 that piece of code changed.

Would help to see the diff between the two to see if the change is relayed,
but i still suspect it is data related not code related.

> If you think that there is a bug, I can open a ticket at the bugtracker.
>
> Thanks!
> --
> Luciano Rossi
> gcoop - Cooperativa de Software Libre
> www.gcoop.coop
> (0054 11) 4855-4390 Juan Ramírez de Velasco 508 Depto A

Reply via email to