Can't set a default origin for stock pickings when duplicating from Python code

Bug #1098557 reported by Numérigraphe
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Committed
Low
OpenERP R&D Addons Team 2
OpenERP Community Backports (Addons)
Fix Released
Wishlist
Lionel Sausin - Initiatives/Numérigraphe

Bug Description

In the Python code of custom addons, it would sometimes be useful to be able to copy a picking while setting the origin field.
For example:
            defaults={'origin': 'test', 'type': 'internal'}
            id = self.pool.get('stock.picking').copy(cr, uid, 1, defaults, context={})
However, in v6.0 and up to the current trunk, the method copy() of stock.picking resets the field "origin" as soon as no default name is set.
I suggest the origin be reset only if it's not passed in the dict of default values.
Lionel Sausin

Related branches

Revision history for this message
Amit Bhavsar (Open ERP) (amb-openerp) wrote :

Hello Numérigraphe,

I have checked your scenario. As per the our architecture when create the new record at that time default value will be set,
but when you duplicate the record at that time copy method will called.
So, obviously default value cant be set at that time. That's why I am set into Question.

Thanks

Changed in openobject-addons:
status: New → Invalid
Revision history for this message
Numérigraphe (numerigraphe) wrote : Re: [Bug 1098557] Re: Can't set a default origin for stock pickings at duplication time

Dear Amit Bhavsar,
I don't understand your remark: a default value can be set by calling
copy() with a dictionnary in the parameter "default", as stated in
http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#id1
Example :
             defaults={'origin': 'test', 'type': 'internal'}
             id = self.pool.get('stock.picking').copy(cr, uid, 1,
defaults, context={})

I've pushed a trivial fix which lets custom addons use it instead of
overriding the value of related key in content of the dictionnary.
Please re-open this bug and/or mark it "Fix committed".
Lionel

description: updated
Changed in openobject-addons:
status: Invalid → New
Revision history for this message
Numérigraphe (numerigraphe) wrote : Re: Can't set a default origin for stock pickings at duplication time

Made the bug report more explicit about the problem: it's from a custom module developer's point of view (calling copy() from python).

Revision history for this message
Amit Parik (amit-parik) wrote :

Hi Lionel,

This kind of behavior works for all copy method.

So if we are confirming this issue then we have to update all the copy method.
There is one big confusion about it, If we are duplicating a record then we create a replica of old record doesn't create a new record, So I think no need to takes the default values.

Also this issue effected to whole addons, that's why setting this as an "Opinion".
Takes the suggestion from community then after decide what to do on this issue.

Thank you!

Changed in openobject-addons:
status: New → Opinion
Revision history for this message
Numérigraphe (numerigraphe) wrote :

Dear Amit Parik,
I hate to insist but it's not a matter of opinion. As per the ORM's API, the copy method MUST accept a dictionary of defaults values to be used instead of the current values when the record is copied.
From the doc:
"default: dictionary of field values to override in the original values of the copied record, e.g: {'field_name': overriden_value, ...}"

Now in stock.picking, several keys in default are not honored (for good reasons !) but origin is reset too and that's not necessary.
Lionel

Changed in openobject-addons:
status: Opinion → New
summary: - Can't set a default origin for stock pickings at duplication time
+ Can't set a default origin for stock pickings when duplicating from
+ Python code
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Lionel,

You have put the MP for this which is fine.
Now I am setting this as a Fix Commited and check what Core team will do.

Thank you!

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 2 (openerp-dev-addons2)
importance: Undecided → Low
status: New → Confirmed
status: Confirmed → Fix Committed
Revision history for this message
Numérigraphe (numerigraphe) wrote : Re: [Bug 1098557] Re: Can't set a default origin for stock pickings when duplicating from Python code

Thanks a lot for your patience, and I hope you didn't take offense that
I insisted.
Lionel.

Changed in ocb-addons:
assignee: nobody → Lionel Sausin - Numérigraphe (lionel-sausin)
importance: Undecided → Low
importance: Low → Wishlist
Changed in ocb-addons:
status: New → Fix Committed
Changed in ocb-addons:
status: Fix Committed → Fix Released
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.