Odoo Help

4
3 Answers
7
Avatar

THOMAS GEORGE

--THOMAS GEORGE--

1014
| 5 4 7
southampton, United Kingdom
--THOMAS GEORGE--


THOMAS GEORGE
2/11/19, 7:14 AM

please refer these documentation.It will help you

https://www.odoo.com/documentation/12.0/howtos/backend.html#wizards

2
Dhaval Desai
2/13/19, 12:54 AM

Hi, 

Geo,

* Odoo Wizard Document Link Given Below Please refer It will definitely help you. :      https://www.odoo.com/documentation/12.0/howtos/backend.html#wizards

* Wizard Example:

1. Create the Transient Model : I have create a new python file salewiz.py under the models directory. The name of our transient model  is : sale.control.limit.wizard. For now, we won’t bother creating fields for it. Let’s keep it basic.

# -*- coding: utf-8 -*-

from odoo import api, models,fields

from odoo.exceptions import UserError

from odoo import exceptions

import logging

_logger = logging.getLogger(__name__)


class SaleConfirmLimit(models.TransientModel):

_name='sale.control.limit.wizard'

invoice_amount = fields.Float('Invoice Amount',readonly=1)

new_balance = fields.Float('Total Balance',readonly=1)

my_credit_limit = fields.Float('Partner Credit Limit',readonly=1)

@api.multi

def agent_exceed_limit(self):

    _logger.debug(' \n\n \t We can do some actions here\n\n\n')

2. Create the XML view file for the Wizard or popup window

<?xml version="1.0" encoding="utf-8"?>

<odoo>

<record model="ir.ui.view" id="my_credit_limit_wizard">

<field name="name">Confirming Sale Order When Credit is Over Limit</field>

<field name="model">sale.control.limit.wizard</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form>

    <group>

          <span>The following customer is about or exceeded their credit limit. This operation needs an Authorized                         Employee to approve the sale order:</span>

    </group>

    <group>

        <field name="invoice_amount" widget="monetary"/>

        <field name="new_balance" widget="monetary"/>

        <field name="my_credit_limit" widget="monetary"/>

    </group>

    <footer>

        <button string="Cancel" special="cancel" class="oe_highlight"/>

        <button name="agent_exceed_limit" string="Request Manager to Approve Sale" type="object"         class="oe_highlight" />

    </footer>

</form>

</field>

</record>

</odoo>

 3. Update the __manifest__.py file to edit the data attribute

'data': [

'views/partner_credit_view.xml',

'views/wizard.confirm.overcredit.xml',

],

4. We may need to create the view with its parameter values  !

params=order.check_credit_limit()

view_id=self.env['sale.control.limit.wizard']

new = view_id.create(params[0])

#The part of the code to initiate the creation of the wizard is shown below:return {

'type': 'ir.actions.act_window',

'name': 'Warning : Customer is about or exceeded their credit limit',

'res_model': 'sale.control.limit.wizard',

'view_type': 'form',

'view_mode': 'form',

'res_id' : new.id,

'view_id': self.env.ref('control_credit_limit.my_credit_limit_wizard',False).id,

'target': 'new',

}

5. As we have extended the sale.order class and we are to override the action_confirm method, we need to return the object to fire off the popup window as follows !

# -*- coding: utf-8 -*-

from odoo import api, models,fields

class MySale(models.Model):

_inherit = "sale.order"

@api.one

def check_credit_limit(self):

    partner=self.partner_id

    new_balance=self.amount_total+partner.credit

    if new_balance>partner.my_credit_limit:

        params = {'invoice_amount':self.amount_total,'new_balance': new_balance,'my_credit_limit':                             partner.my_credit_limit}

        return params

    else:

        return True

@api.multi

def action_confirm(self):

    for order in self:

        params=order.check_credit_limit()

        view_id=self.env['sale.control.limit.wizard']

        new = view_id.create(params[0])

    return {

                'type': 'ir.actions.act_window',

                'name': 'Warning : Customer is about or exceeded their credit limit',

                'res_model': 'sale.control.limit.wizard',

                'view_type': 'form',

                'view_mode': 'form',

                'res_id' : new.id,

                'view_id': self.env.ref('control_credit_limit.my_credit_limit_wizard',False).id,

                'target': 'new'}

#res = super(MySale, self).action_confirm()

#return res

6. That’s it! we have created a simple wizard popup window.


Thank You.


Ask a Question
Writer
115
geo
Tag
Keep Informed
1 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now