This question has been flagged

hello,

1)i made some custom field in product.template, now i would like to get them in purchase order form view. any help?

2)it's possible to add the value of the field after another? for example i have product id, name, default_code ecc on product.template.product.form. now i would like that in purchase order, when i select a product , it fill the description with name+default_code


thanks

Avatar
Discard
Best Answer

Hi aneli,
Its possible, 

In purchase module there is function

class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'

def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty,
uom_id, partner_id, date_order=False,
fiscal_position_id=False, date_planned=False,
name=False, price_unit=False, state='draft',
context=None):
res = super(PurchaseOrderLine, self).onchange_product_id(
cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id,
date_order=date_order, fiscal_position_id=fiscal_position_id,
date_planned=date_planned, name=name, price_unit=price_unit,
state=state, context=context)
         product_id = res['product_id']
         res['name'] = product_id.name + product_id.default_code
         # for addind  "x_IDfornitore" and x_IDfornitore2 fields
          res['name'] = product_id.name (if needed,) + product_id.x_IDfornitore + IDfornitore2
return res

** Please remove (if needed,) from code.

Please super this function and make what you want.

This is just a model, you can make it as you like. (Don't follow the exact code, its model)

If you need a correct code, you make your question more detailed.

Thank you, hope it will help you.

Avatar
Discard
Author Best Answer

thanks very much and sorry but i'm really newbi to programmin.


when i get to change the code i found that the code you gave me is for odoo 9. in odoo 8 i found this

class purchase_order_line(osv.osv):

    def _calc_line_base_price(self, cr, uid, line, context=None):

        """Return the base price of the line to be used for tax calculation.

        This function can be extended by other modules to modify this base

        price (adding a discount, for example).

        """

        return line.price_unit

    def _calc_line_quantity(self, cr, uid, line, context=None):

        """Return the base quantity of the line to be used for the subtotal.

        This function can be extended by other modules to modify this base

        quantity (adding for example offers 3x2 and so on).

        """

        return line.product_qty

    def _amount_line(self, cr, uid, ids, prop, arg, context=None):

        res = {}

        cur_obj=self.pool.get('res.currency')

        tax_obj = self.pool.get('account.tax')

        for line in self.browse(cr, uid, ids, context=context):

            line_price = self._calc_line_base_price(cr, uid, line,

                                                    context=context)

            line_qty = self._calc_line_quantity(cr, uid, line,

                                                context=context)

            taxes = tax_obj.compute_all(cr, uid, line.taxes_id, line_price,

                                        line_qty, line.product_id,

                                        line.order_id.partner_id)

            cur = line.order_id.pricelist_id.currency_id

            res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])

        return res

    def _get_uom_id(self, cr, uid, context=None):

        try:

            proxy = self.pool.get('ir.model.data')

            result = proxy.get_object_reference(cr, uid, 'product', 'product_uom_unit')

            return result[1]

        except Exception, ex:

            return False

    _columns = {

        'name': fields.text('Description', required=True),

        'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),

        'date_planned': fields.date('Scheduled Date', required=True, select=True),

        'taxes_id': fields.many2many('account.tax', 'purchase_order_taxe', 'ord_id', 'tax_id', 'Taxes', domain=['|', ('active', '=', False), ('active', '=', True)]),

        'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True),

        'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok','=',True)], change_default=True),

        'move_ids': fields.one2many('stock.move', 'purchase_line_id', 'Reservation', readonly=True, ondelete='set null'),

        'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),

        'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account')),

        'order_id': fields.many2one('purchase.order', 'Order Reference', select=True, required=True, ondelete='cascade'),

        'account_analytic_id':fields.many2one('account.analytic.account', 'Analytic Account',),

        'company_id': fields.related('order_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),

        'state': fields.selection([('draft', 'Draft'), ('confirmed', 'Confirmed'), ('done', 'Done'), ('cancel', 'Cancelled')],

ecc ecc


it's similar or i need to write a different code?


thank

Avatar
Discard

Hai friend, i think In the XML you did not make any change, so you need to add this 2 values( "x_IDfornitore" and x_IDfornitore2) in name field in purchase order,

So you just check my above answer once more, i will rewrite it for you, please check that this fields ( "x_IDfornitore" and x_IDfornitore2) defined in product.template. ok

Author

i'm sorry but the function you gave me is in the purchase.py from odoo 9. i change my answare with the code i found in odoo 8 versione of purchase.py. i don't if it's the same

Author

on odoo 8 this function "class PurchaseOrderLine(models.Model)" is different . it's purchase_order_line(osv.osv) ecc. the code still works or i need a different one?

thanks

Best Answer

Of course it's possible. You need to make an inheritance of purchase.order.line for rewrite the onchange_product_id method, in this method you can put into description field anything you want.

Avatar
Discard