Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Returns the default price unity in Odoo/OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 633
    Comment on it

    In res.partner method we can returns the default price unity on run time and we can access the default price unity in Odoo server. For example you can see below code.

    from openerp import api
    from openerp.osv import osv, fields
    from openerp.tools.translate import _
    
    _logger = logging.getLogger('rent')
    
    class Product(osv.osv):
        
        def check_rent_price(self, cr, uid, ids, context=None):
            """
            We check that the rent price is neither empty or 0 if the product can be rent.
            """
            products = self.browse(cr, uid, ids)
    
            for product in products:
                if product.can_be_rent:
                    if not product.rent_price or product.rent_price <= 0:
                        return False
            return True
         
        def default_price_unity(self, cr, uid, ids,  context=None):
            """
            Returns the default price unity (the first in the list).
            """   
            unity1 = self.pool('product.uom').search(cr, uid, [])[16]
            print"===========unity1==========",unity1
            unity = self.pool('product.uom').browse(cr, uid, unity1)
            if not unity:
                _logger.warning("It seems that there isn't a reference unity in the 'Duration' UoM category. "
                                "Please check that the category exists, and there's a refernce unity.")
            if unity: 
                return unity.id
            else:
                return False
        
          
    #     def action_view_stock_movess(self, cr, uid, ids, context=None):
    #         result = {}
    #         products = self._get_products(cr, uid, ids, context=context)
    #         print"========products22========",products
    #         result = self._get_act_window_dict(cr, uid, 'rent.act_product_stock_move_opens', context=context)
    #         print"========result22========",result
    #         if products:
    #             result['context'] = "{'default_product_id': %d}" % products[0]
    #             print"========result['context']===========",result['context']
    #         result['domain'] = "[('product','in',[" + ','.join(map(str,ids)) + "])]"
    #         return result
    
    
    
    #     @api.multi
    #     @api.depends('product_variant_ids.rent_count')
    #     def _rent_count(self):
    #         for product in self:
    #             product.rent_count = sum([p.rent_count for p in product.product_variant_ids])
    #      
     
        @api.multi
        def action_view_rent(self):
            self.ensure_one()
            action = self.env.ref('rent.action_product_rent_list')
            product_ids = self.product_variant_ids.ids
     
            return {
                'name': action.name,
                'help': action.help,
                'type': action.type,
                'view_type': action.view_type,
                'view_mode': action.view_mode,
                'target': action.target,
                'context': "{'search_default_product_id': " + ','.join(map(str, product_ids)) + ", 'default_product_id': " + str(product_ids[0]) + "}",
                'res_model': action.res_model,
                'domain': action.domain,
            }
        
    
        _name = 'product.template'
        _inherit = 'product.template'
    
        _columns = {
       #             'rent_count' :fields.function(_rent_count, ' Rent'),  
                    'can_be_rent' : fields.boolean('Can be rented', help='Enable this if you want to rent this product.'),
                    'rent_price' : fields.float('Rent price', help='The price is expressed for the duration unity defined in the company configuration.'),
                    'rent_price_unity' : fields.many2one('product.uom',  'Rent Price Unity',help='Rent duration unity in which the price is defined.'),
    
        }
    
        _defaults = {
            'can_be_rent' : False,
            'rent_price' : 1.0,
            'rent_price_unity' : default_price_unity,
    
        }
    
        _constraints = [(check_rent_price, _('The Rent price must be a positive value.'), ['rent_price']),]
    
    Product()

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: