This question has been flagged
1 Reply
7153 Views

Hi everyone

Sorry because I'm not good at English.

I want to modify default value of "source location" and "destination location". So, my problem is the value of Location when I create a "Receive/Deliver Products -> Incoming Products" has been changed. But after that, about 1 second, It return the old value as model "stock.move" define it.

But when I create a "Receive/Deliver By Orders -> Incoming Shipments" and click "Add an items", the value of Location same the value I modify in my module

So, do you understand me?

from openerp.osv import fields, osv, orm
from openerp.tools.translate import _
from openerp import tools
from openerp.tools import float_compare, DEFAULT_SERVER_DATETIME_FORMAT

class default_location(osv.osv):

    _inherit = 'stock.move'
    
    def _default_location_destination(self, cr, uid, context=None):
       """some thing here"""

        return location_id

    def _default_location_source(self, cr, uid, context=None):
        """some thing here"""

        return location_id

    _columns = {
         'location_id': fields.many2one('stock.location', 'Source Location', required=True, select=True,states={'done': [('readonly', True)]}, help="Sets a location if you produce at a fixed location. This can be a partner location if you subcontract the manufacturing operations."),
        'location_dest_id': fields.many2one('stock.location', 'Destination Location', required=True,states={'done': [('readonly', True)]}, select=True, help="Location where the system will stock the finished products."),
    }

    _defaults = {
        'location_id': _default_location_source,
        'location_dest_id': _default_location_destination,
    }

default_location()

 

So? What is wrong?

Help me! Thank you so much

Avatar
Discard

what do you mean by "they returned the last value right now, as I didn't modify them" ?? So, according to your question _defaults works fine. so what is your question? Describe the problem in detail

Hi atchuthan

Sorry because I'm not good at English.
I want to modify default value of "source location" and "destination location". So, my problem is the value of Location when I create a "Receive/Deliver Products -> Incoming Products" has been changed. But after that, about 1 second, It return the old value as model "stock.move" define it.
But when I create a "Receive/Deliver By Orders -> Incoming Shipments" and click "Add an items", the value of Location same the value I modify in my module
So, do you understand me?




2014-08-07 12:12 GMT+07:00 atchuthan <atchuthantu@mail.odoo.com>:

what do you mean by "they returned the last value right now, as I didn't modify them" ?? So, according to your question _defaults works fine. so what is your question? Describe the problem in detail

--
atchuthan Sent by Odoo Inc. using Odoo. Access your messages and documents in Odoo



--
Trần Như Văn
MSSV: 51104177
K11 Bách Khoa Tp.HCM
Khoa: Khoa học và Kĩ thuật máy tính
Author Best Answer

Help me, please

Here is my function, but it didn't work.

def _default_location_destination(self, cr, uid, context=None):
        """ Gets default address of partner for destination location
        @return: Address id or False
        """
        super(default_location, self)._default_location_destination(cr, uid, context)
        mod_obj = self.pool.get('ir.model.data')
        picking_type = context.get('picking_type')
        location_id = False
        location_xml_id = False
        if picking_type in ('in', 'internal'):
            location_xml_id = 'stock_location_customers'
        elif picking_type == 'out':
            location_xml_id = 'stock_location_customers'
        if location_xml_id:
            try:
                location_model, location_id = mod_obj.get_object_reference(cr, uid, ['company','stock'], location_xml_id)
                with tools.mute_logger('openerp.osv.orm'):
                    self.pool.get('stock.location').check_access_rule(cr, uid, [location_id], 'read', context=context)
            except (orm.except_orm, ValueError):
                location_id = False
        return location_id

Avatar
Discard