Skip to Content
Menu
This question has been flagged
1 Reply
5088 Views

Hi,

I give the smart button of create RFQ 

Py file

class createRfq (models.Model):
_inherit = 'product.template'
create_rfq = fields.Integer ('RFQ')

def action_view_rfq (self):
products = self.mapped ('product_variant_ids')
action = self.env.ref (' purchase.purchase_form_action '). read () [0]
if products and len (products) == 1:
action ['context'] = {'default_product_id': products.ids [0], 'search_default_product_id': products.ids [0], 'default_partner_id' : 16}
else:
action ['domain'] = [('product_id', 'in', products.ids)]
action ['context'] = {}
return action


Xml file

<odoo>
<record model = "ir.actions.act_window" id = "create_rfq">
<field name = "context"> {'default_product_id': active_id, 'search_default_product_id': active_id} </field>
<field name = " name "> Reordering Rules </field>
<field name =" res_model "> purchase.order </field>
</record>

<record id =" product_template_form_create_rfq_button "model =" ir.ui.view ">
<field name =" name "> product.template.procurement </field>
<field name =" model "> product.template </field>
<field name =" inherit_id "ref = "product.product_template_only_form_view" />
<! - <field name = "groups_id" eval = "[(4, ref ('mrp.group_mrp_user'))]" /> ->
<field name = "arch" type = "xml">
<button name = "toggle_active" position = "before">
<button type = "object" name = "action_view_rfq" class = "oe_stat_button" icon = "fa-refresh" >
<field name = "create_rfq" widget = "statinfo" />
</button>
</button>
</field>
</record>


</odoo>
Thanks 

Avatar
Discard
Best Answer

Hi,

You can use the default_get function for this. Inside the default_get function, check whether there is product_id in the context, if exist you can create an order line with the product as product passed in the context.

See how to write default get function: https://www.youtube.com/watch?v=14mc1fIbVuU

Try this:

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

@api.model
def default_get(self, fields):
res = super(PurchaseOrder, self).default_get(fields)
#check context whether product is there or not using
# if context.get('product_id'):
order_line = []
line = (0, 0, {'product_id': product_id}) #assume product_id is variable having id of product
# pass all required values inside the dictionary
# product_id is only passed now, qty, price etc will be required
order_line.append(line)
res.update({
'order_line': order_line,
})
return res

Thanks

Avatar
Discard