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.

1

How to fill list of products on purchase quotation? [Closed]

By
Luís
on 4/8/13, 9:29 AM 3,219 views

The Question has been closed

by
Sudhir Arya (SA)
on 04/18/2013 05:25:55

Hi,

I'm trying to fill the products of purchase order. For this, I create a module that link sale quotation to purchase quotation. With this module I can select the sale quotation associated for my new purchase quotation (how we can see in the picture below). At this time when I select the sale quotation associated a my new purchase quotation, the products from the sale quotation appears on purchase order. So far so good, but the edit inline doesn't work and the button "Save" don't save the information.

Anyone know what I'm doing wrong on my code?


image description

mymodule.py

class purchase_order(osv.osv):

    _inherit = 'purchase.order'
    _name = 'purchase.order'

    _columns = {
       'asd_pquotation_id': fields.many2one('sale.order','Sale Quotation', domain=[('state','in',('draft','sent'))]),
    }
    _defaults = {
        'asd_pquotation_id': lambda self, cr, uid, context: context.get('asd_pquotation_id', False),
    }

    def onchange_sales_order(self, cr, uid, id, asd_pquotation_id, date_order, context=None):
        res = []
        if asd_pquotation_id:
            so = self.pool.get('sale.order').browse(cr,uid,asd_pquotation_id)
            for sol in so.order_line:
                val = {
                    'product_id': sol.product_id and sol.product_id.id,
                    'product_qty': sol.product_uom_qty,
                    'product_uom': sol.product_uom and sol.product_uom.id,
                }
                res.append(val)
        return {'value': {'order_line': res}}

purchase_order()

class sale_order(osv.osv):
    _inherit = "sale.order"
    _name = "sale.order"
    _columns = {
        'vi_contact_by': fields.selection([ ('by1','Email'), ('by2','Fax'), ('by3','Phone'), ], 'Contacted by'),
        'asd_squotation': fields.one2many('purchase.order','asd_pquotation_id', 'Purchase Quotation'),
    }
sale_order()

mymodule_view.xml

<record id="purchase_order_form_change" model="ir.ui.view">
        <field name="name">purchase.order.form.change</field>
        <field name="model">purchase.order</field>
        <field name="inherit_id" ref="purchase.purchase_order_form"/>
        <field name="arch" type="xml">
        <xpath expr="/form/sheet/group/group/field[@name='company_id']" position="after">
                <field name="asd_pquotation_id" on_change="onchange_sales_order(asd_pquotation_id, context)"/>
            </xpath>
    </field>
</record>

You may have to use MTO on products, that is doing what you want to develop in another way (but more clean)

Fabien Pinckaers (fp)
on 4/10/13, 3:06 AM
0

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/9/13, 8:06 AM

Try this:

Add on_change in your field:

<field name="asd_pquotation_id" on_change="onchange_purchase_order(asd_pquotation_id,partner_id,pricelist_id)"/>

    def onchange_sales_order(self, cr, uid, id, asd_pquotation_id, partner_id, pricelist_id):
        domain = []
        value = []
        if asd_pquotation_id:
            so = self.pool.get('sale.order').browse(cr,uid,asd_pquotation_id)
            for sol in so.order_line:
                vals = self.pool.get('purchase.order.line').onchange_product_id(cr, uid, ids, pricelist_id, sol.product_id.id, sol.product_uom_qty, sol.product_uom.id, partner_id)
                vals['value'].update({
                  'product_id': sol.product_id.id,
                  'state': 'draft',
                })
                value.append(vals['value'])
                domain.append(vals['domain'])
        return {'value': {'order_line': value}, 'domain': {'order_line': domain}}

Thank you.

openerp.sql_db: bad query: insert into "purchase_order_line" (id,"product_id","product_uom","date_planned","order_id","price_unit","company_id","name","state","product_qty","account_analytic_id","invoiced",create_uid,create_date,write_uid,write_date) values (4,2,1,'2013-04-09 00:00:00',4,'0.00',NULL,'Folic Acid',NULL,'1.000',NULL,'False',1,(now() at time zone 'UTC'),1,(now() at time zone 'UTC')) Traceback (most recent call last):   File "/opt/openerp-7.0/openerp/sql_db.py", line 227, in execute     res = self._obj.execute(query, params) IntegrityError: null value in column "state" violates not

Luís
on 4/9/13, 1:01 PM

Hi, While I was trying the previous solution, I faced the following error regarding sql constraints while trying to create a new purchase_order_line: (...)res = self._obj.execute(query, params) IntegrityError: null value in column "state" violates not-null constraint Having a look at this class I found: (...) _defaults = { 'product_qty': lambda *a: 1.0, 'state': lambda *args: 'draft', 'invoiced': lambda *a: 0, } (...) Why are these values being discarded?

Luís
on 4/9/13, 1:02 PM

See my updated answer.

Sudhir Arya (SA)
on 4/10/13, 2:12 AM
0
arif
On 4/9/13, 7:58 AM

Modify the function onchange_sales_order as following and try

   def onchange_sales_order(self, cr, uid, id, asd_pquotation_id, date_order, context=None):
        res = []
        if asd_pquotation_id:
            so = self.pool.get('sale.order').browse(cr,uid,asd_pquotation_id)
            for sol in so.order_line:
                val = {
                    'product_id': sol.product_id and sol.product_id.id,
                    'product_qty': sol.product_uom_qty,
                    'product_uom': sol.product_uom and sol.product_uom.id,
                }
                res.append((0,0,val))
        return {'value': {'order_line': res}}

openerp.sql_db: bad query: insert into "purchase_order_line" (id,"product_id","product_uom","date_planned","order_id","price_unit","company_id","name","state","product_qty","account_analytic_id","invoiced",create_uid,create_date,write_uid,write_date) values (4,2,1,'2013-04-09 00:00:00',4,'0.00',NULL,'Folic Acid',NULL,'1.000',NULL,'False',1,(now() at time zone 'UTC'),1,(now() at time zone 'UTC')) Traceback (most recent call last):   File "/opt/openerp-7.0/openerp/sql_db.py", line 227, in execute     res = self._obj.execute(query, params) IntegrityError: null value in column "state" violates not

Luís
on 4/9/13, 12:56 PM

Hi,

While I was trying the previous solution, I faced the following error regarding sql constraints while trying to create a new purchase_order_line: (...)res = self._obj.execute(query, params) IntegrityError: null value in column "state" violates not-null constraint

Having a look at this class I found: (...) _defaults = { 'product_qty': lambda *a: 1.0, 'state': lambda *args: 'draft', 'invoiced': lambda *a: 0, } (...)

Why are these values being discarded?

Luís
on 4/9/13, 12:59 PM

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 4/8/13, 9:29 AM
Seen: 3219 times
Last updated: 3/16/15, 8:10 AM