Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How can I change field value in _default

By
NhuVanTran
on 8/6/14, 5:26 AM 1,918 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

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 - Technical Consultant, Sodexis Inc
on 8/7/14, 1:12 AM
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
NhuVanTran
on 8/7/14, 1:59 AM
0
NhuVanTran
On 8/6/14, 10:58 PM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 8/6/14, 5:26 AM
Seen: 1918 times
Last updated: 3/16/15, 8:10 AM