Skip to Content
Menu
This question has been flagged

Hello All,

I selected customer name in sales order form. And above the sale order line i added a button, for this button wizard is opened and getting information from customer. I want that in wizard customer name(partner_id) should be auto field when user open it. So, ho can i do that?

Wizard file code is:

class RentalPackWizard(models.TransientModel):

    _name = "rental.pack.wizard"

    _description = "Rental Pack Wizard"

"""@api.model

    def _get_default_partner(self):

        partner = self.env['res.partner'].search([()], limit=1)

        return partner"""

    ser6_partner_id = fields.Many2one('res.partner', string='Customer')# , default=_get_default_partner)


Also Attached image for problem

 

Avatar
Discard
Best Answer

Hi Pawan,

You can access the sales order record as active_ids from self._context and then access the partner.

@api.model
def _get_default_partner(self):
ctx = self._context
if ctx.get('active_model') == 'sale.order':
return self.env['sale.order'].browse(ctx.get('active_ids')[0]).partner_id.id

Hope this solve your problem.

Sudhir Arya
ERP Harbor Consulting Services
skype: sudhir@erpharbor.com  website: http://www.erpharbor.com
Avatar
Discard
Author

Hello @Sudhir, i tried your method but i don't get default customer, also after choosing customer and save wizard then it shows error for "Product Unit of Measure - product.uom". So, i ho to get default customer on wizard.

Thanks for your reply..

Would you please share your module or code?

Author

Hii @Sudhir, Here is my python code:

class RentalPackWizard(models.TransientModel):

_name = "rental.pack.wizard"

_description = "Rental Pack Wizard"

@api.model

def _get_default_service6(self):

service = self.env['product.product'].search([('type_service', '=', 'd')], limit=1)

return service

@api.model

def _get_default_partner(self):

ctx = self._context

if ctx.get('active_mode') == 'sale.order':

return self.env['sale.order'].ctx.get('active_ids')[0].partner_id.id

check_ser6 = fields.Boolean(string='Include In sales order')

product_id_ser6 = fields.Many2one('product.product', string='Service', default=_get_default_partner)

ser6_partner_id = fields.Many2one('res.partner', string="Customer")

ser6_price = fields.Float('Price')

ser6_weight = fields.Many2one('est.weight', string='Weight')

ser6_actual_weight = fields.Float("Actual Weight(Kg)")

@api.multi

def action_rentalpack_add(self):

rec = self._context.get('active_ids', [])

print "REntal", rec, self.product_id_rental.categ_id

g1 = []

if rec:

hydro_treat = {'product_id': self.product_id_ser6.id,

'category_id': self.product_id_ser6.categ_id.id,

'product_uom': self.product_id_ser6.uom_id.id,

# 'product_uom': 1,

'order_id': rec[0],

'price_unit': self.ser6_price

if self.check_ser6 is True:

sale_order_line6 = self.env['sale.order.line'].create(hydro_treat)

xml code:

<page string="Hydrolysis Treatment">

<group string="Hydrolysis Treatment" col="4" colspan="4">

<field name="check_ser6" context="{'default_partner_id':partner_id}"/>

<field name="product_id_ser6" readonly="1"/>

<field name="ser6_partner_id"/>

<field name="ser6_weight"/>

<field name="ser6_actual_weight"/>

<field name="ser6_price"/>

</group>

</page>

Hi Pawan,

It was my mistake. I did typo mistake in the code.

if ctx.get('active_mode') == 'sale.order'

Here, it should be active_model and not active_mode.

I have corrected the code. Please try that and give feedback.

Author

Hello Sudhir i still getting error: "File "/opt/odoo10/odoo/odoo/addons/rental/rental_pack.py", line 401, in _get_default_partner

return self.env['sale.order'].ctx.get('active_ids')[0].partner_id.id

AttributeError: 'sale.order' object has no attribute 'ctx'"

for - if ctx.get('active_model') == 'sale.order':

Updated the code in answer. This should work now.

Author

Thanks Sudhir it's work. i added "change_default=True" in field after-that it works.

Glad to know that its working fine now.

Author

Hello Sudhir, when click on "OK" button on wizard then it show error "[object with reference: Product Unit of Measure - product.uom] " for this method. When i make method disable value return. So, how to solve this?

Author

Now, done. Thank's Sudhir....!!

Related Posts Replies Views Activity
0
Aug 17
2343
0
Nov 18
5119
1
Jun 18
4000
1
Jun 17
3963
2
Jan 18
3114