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

Hi All Need help with adding fields to sales order.

By
Lucien Paulsen
on 8/14/13, 9:24 AM 842 views

Hi Guys

I've been toying with adding 2 fields to the sale.order and account.invoice objects. The need arose after a certain client needs to identify themseives to there client via this numbers for delivery to a branch. The additions to the code were made in sale.py and account_invoice.py and there respective form views. the columns added where also added to res.partner. Here is my additions to the sales.py and account_Iinvoice.py.

_columns = {

    'supplier_number':fields.char('Supplier Number', size = 25 , required = False, readonly=True),
    'branch_number':fields.char('Branch Code',size=10, required = False, readonly=False),

}

The problem comes in getting the values to the fields. When i ad the following to the sale onchange_partner_id method

def onchange_partner_id(self, cr, uid, ids, part, context=None):
        if not part:
            return {'value': {'partner_invoice_id': False, 'partner_shipping_id': False,  'payment_term': False, 'fiscal_position': False}}
    part = self.pool.get('res.partner').browse(cr, uid, part, context=context)
    addr = self.pool.get('res.partner').address_get(cr, uid, [part.id], ['delivery', 'invoice', 'contact'])
    pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False
    payment_term = part.property_payment_term and part.property_payment_term.id or False
    fiscal_position = part.property_account_position and part.property_account_position.id or False
    dedicated_salesman = part.user_id and part.user_id.id or uid
    suppnum = part.x_Supplier_Number 
    branchnum = part.ref
    val = {
        'partner_invoice_id': addr['invoice'],
        'partner_shipping_id': addr['delivery'],
        'payment_term': payment_term,
        'fiscal_position': fiscal_position,
        'user_id': dedicated_salesman,
        'supplier_number':suppnum,
        'branch_number':branchnum,
     }
    if pricelist:
        val['pricelist_id'] = pricelist
    return {'value': val}

I have also edited the _prepare_invoice method to include updating the fields for invoice creation. as follows.

def _prepare_invoice(self, cr, uid, order, lines, context=None):
        """Prepare the dict of values to create the new invoice for a
           sales order. This method may be overridden to implement custom
           invoice generation (making sure to call super() to establish
           a clean extension chain).
       :param browse_record order: sale.order record to invoice
       :param list(int) line: list of invoice line IDs that must be
                              attached to the invoice
       :return: dict of value to create() the invoice
    """
    if context is None:
        context = {}
    journal_ids = self.pool.get('account.journal').search(cr, uid,
        [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)],
        limit=1)
    if not journal_ids:
        raise osv.except_osv(_('Error!'),
            _('Please define sales journal for this company: "%s" (id:%d).') % (order.company_id.name, order.company_id.id))
    invoice_vals = {
        'name': order.client_order_ref or '',
        'origin': order.name,
        'type': 'out_invoice',
        'reference': order.client_order_ref or order.name,
        'account_id': order.partner_id.property_account_receivable.id,
        'partner_id': order.partner_invoice_id.id,
        'journal_id': journal_ids[0],
        'branch_number': order.branch_number,
        'supplier_number': order.supplier_number,
        'invoice_line': [(6, 0, lines)],
        'currency_id': order.pricelist_id.currency_id.id,
        'comment': order.note,
        'payment_term': order.payment_term and order.payment_term.id or False,
        'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
        'date_invoice': context.get('date_invoice', False),
        'company_id': order.company_id.id,
        'user_id': order.user_id and order.user_id.id or False
    }

    # Care for deprecated _inv_get() hook - FIXME: to be removed after 6.1
    invoice_vals.update(self._inv_get(cr, uid, order, context=context))
    return invoice_vals

This works fine and loads the values of supplier Number and branch code perfectly. My problem is such that.

  1. When i hit the update button the supplier number disappears and ( i suspect this is in button_dummy method please confirm).

  2. When i need the branch number for a delivery address which is stored in the res.partner.child_ids.category_id.id field in the res.partner i do not know how to reference the field. Should i store this in child_ids.ref rather. And then create a onchange_parnter_shipping_id method to call when delivery address changes.

I would appreciate any assistance thank You

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

1 follower(s)

Stats

Asked: 8/14/13, 9:24 AM
Seen: 842 times
Last updated: 3/16/15, 8:10 AM