How to get values from odoo context in qweb templating in odoo 9? - odoo

I'm working in odoo 9. I have opened a wizard from JS and in that I have passed context, I want to use this context in my wizard. How can I do this?
Please see my code.
myfunc: function(e) {
var mycontext = {};
var is_checked = this.field_manager.get_field_value('Default')
if (is_checked)
{
var model_obj = new Model('olims.ar_priority');
var domain = [['Default', '=', true]];
model_obj.call('search_read',[domain]).then(function(result){
mycontext['current_priority'] = result[0]['Priority'];
})
alert()
this.do_action({
name: ("Pop Up"),
res_model: 'olims.ar.priority.wizard',
type: 'ir.actions.act_window',
view_type: 'form',
view_mode: 'form',
views: [
[false,'form']
],
target: 'new',
context : mycontext,
});
}
and this is xml
<record model="ir.ui.view" id="olims_ar_priority_confirm_wizard">
<field name="name">Set Default Priority Wizard</field>
<field name="model">olims.ar.priority.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<group>
<templates>
<t t-set="priority" t-value="request.env.context['current_priority']"/>
<span><t t-esc="priority"/> is set as default</span>
</templates>
</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>

Related

How to send context to wizard and add reference from Form in Odoo 13

so I Have several fields in my Wizard model that the default value is the same from the form but we can change it. I try to send my form field value using context but it has an error like this
odoo.tools.convert.ParseError: ": "name
'arrival_date' is not defined"
while evaluating. The name of the field already right because when I use context in my line or one2many field It works just fine.
And Second when I create the record its not referencing my form record. Do I need to change the default write method?
<record model="ir.ui.view" id="kre_product_reservation_wizard_form_view">
<field name="name">kre.product_reservation.form</field>
<field name="model">kre.product_reservation</field>
<field name="arch" type="xml">
<form string="Add Attendees">
<group>
<group>
<!-- Add your fields here -->
<field name="reservation_number"/>
<field name="arrivals_date"/>
<field name="departure_date"/>
<field name="stay_period"/>
<field name="qty"/>
<field name="price"/>
<field name="tax"/>
<field name="sub_amount"/>
<field name="tax_amount"/>
<field name="amount"/>
<field name="description"/>
</group>
<notebook>
<page string="Guest List">
<field name="guests"/>
</page>
</notebook>
</group>
</form>
</field>
</record>
<act_window id="insert_reservation_wizard" name="Insert Reservation" context="{'reservation_id' : active_id, 'arrival_date' : arrival_date, 'departure_date' : departure_date}" binding_model="kre.reservation" res_model="kre.product_reservation" view_mode="form" target="new"/>
And this is the binding model Field that I want to send in Context.
<field name="name"/>
<field name="billing_name"/>
<field name="arrival_date"/>
<field name="departure_date"/>
<field name="group"/>
<field name="currency"/>
<field name="sub_total"/>
<field name="tax"/>
<field name="total"/>
Hello Theodorus Agum Gumilang,
On your act_window you can set the model id or any selection or boolean from the default context passing. Like this,
<act_window id="insert_reservation_wizard"
name="Insert Reservation"
binding_model="kre.reservation"
res_model="kre.product_reservation"
view_mode="form"
context="{'default_reservation_id' : active_id, 'reservation_id' : active_id}"
target="new"/>
You can check the other reference on odoo for default value set from act_window. As on your default value set from the form itself on wizard view, you can do with by changing the approach this way,
1) Calling your wizard action from the python.
2) On the python, you can pass the default value on context.
On you form view added the button,
<button name="action_wizard" string="Your String" type="object" class="btn-primary" />
On Python Function,
def action_wizard(self):
return {
'name': _("Your String"),
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'Object',
'view_id': self.env.ref('module.ref_id').id,
'target': 'new',
'context': {
'default_name': self.default_name,
'default_billing_name': self.default_billing_name,
'default_arrival_date': self.default_arrival_date,
'default_departure_date': self.default_departure_date,
'default_group': self.default_group,
'default_currency': self.default_currency,
'default_sub_total': self.default_sub_total,
'default_tax': self.default_tax,
'default_total': self.default_total
}}
Thanks

How close a popup model with after saving in odoo 13

I have a problem when i want to close a popup model, only save the data but i want return to invoice.
I open this module from invoice but i want that only close after save not create a new invoice.
something help me please
my code xml
<record id="create_autorizacion_form" model="ir.ui.view">
<field name="name">autorizacion.autorizacion.wizard</field>
<field name="model">autorizacion.autorizacion</field>
<field name="arch" type="xml">
<form string="AutorizaciĆ³n">
<group >
<field name="invoice_amount"/>
<field name="new_balance"/>
<field name="my_credit_limit"/>
</group>
<xpath expr="//sheet" position="after">
<footer>
<button string="Confirm" name="create_autorization" class="btn-primary" special="save"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</xpath>
</form>
</field>
my code .py
class autorizacion(models.Model):
_name="autorizacion.autorizacion"
invoice_amount = fields.Float('Invoice Amount')
new_balance = fields.Float('Total Balance')
my_credit_limit = fields.Float('Partner Credit Limit')
#api.model
def create_autorization(self,vals):
print("funciona")
view = {
'context': self.env.context,
'view_type': 'list',
'view_mode': 'form',
'res_model': 'account.move',
'res_id': self.id,
'view_id': False,
'type': 'ir.actions.act_window',
'nodestroy': False,
'domain': '[]',
'target': 'self',
}
return view
you are trying to create a wizard so for module declaration you need juste to change
this :
class class autorizacion(models.Model):
to this :
class autorizacion(models.TransientModel) :
hope this will help you

Create a dynamic Wizard with links to download pdf files

I'm trying to create a report button in:
view: account_payment.view_payment_order_form
model: payment.order
Accounting -> Payment -> Rec. Payment order -> FORM
My goal is to obtain each line of 'line_ids' and open a Wizard that populates with a download link for each line of 'line_ids'.
For the moment I'm trying to create a dynamic Wizard with no luck. I don't know if it is possible to do this.
Thanks for the answers.
Wizard model:
class my_wizard(osv.TransientModel):
_name = 'my_wizard'
_columns = {
'line_ids': fields.one2many('payment.order', 'Payment order'),
}
Call wizard (in "payment.order" model):
def call_wizard(self, cr, uid, ids, context):
my_wizard_form_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment', 'my_wizard_form')[1]
lines = []
for line in self.browse(cr, uid, ids, context).line_ids:
lines.append([0, 0, {'line_id': line.id}])
#To create records dyamically
ctx={'default_line_ids': lines}
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'my_wizard',
'views': [(my_wizard_form_id, 'form')],
'view_id': my_wizard_form_id,
'target': 'new',
'context': ctx,
}
Wizard view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="my_wizard_form" model="ir.ui.view">
<field name="name">my_wizard.form</field>
<field name="model">my_wizard</field>
<field name="type">form</field>
<field name="arch" type="xml" >
<form>
<field name="line_ids" widget="one2many_list">
<tree editable="bottom">
<field name="id"/>
<!-- define "download" function in "payment.line"
<button name='download' type='object' string='download' />
</tree>
</field>
<field name='' />
</group>
</form>
</field>
</record>
<record id="action_my_wizard_form" model="ir.actions.act_window">
<field name="name"></field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">my_wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
Button to call wizard (payment_order view):
<button name='call_wizard' type="object" string="WIZARD" />
You should create download method in payment.line model.
def download(self, cr, uid, ids, context):
#To open an URL
'''return {
"type": "ir.actions.act_url",
"url": "LINK TO PDF",
"target": "self",
}
'''
#To generate a report
datas = {
'ids': ids,
'model': 'dossier',
'form': self.read(cr, uid, ids[0], context=context)
}
return {
'type': 'ir.actions.report.xml',
'report_name': 'my_report',
'datas': datas,
'nodestroy': True
}
I hope this will be useful.

getting error like relation "_unknown" does not exist?

I have created one model, It contain 2 fields and one grid view. So I am trying to many2one for one field to create new id. Please let me know where i am making the mistake ?
.py code is here
from openerp.osv import fields, osv
class agile_portfolio(osv.Model):
_name = "agile.portfolio"
_rec_name = 'epic_owner'
_columns = {
'name': fields.char('Asset Name',),
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID'),
'strat_id1' : fields.one2many('portfolio.grid','strat_id','Strategy Name'),
}
agile_portfolio()
class portfolio_grid(osv.Model):
_name = 'portfolio.grid'
_columns = {
'name' : fields.char('Part'),
'strat_code' : fields.char('Code'),
'strat_quty' : fields.char('Quantity '),
'strat_uom' : fields.char('UoM'),
'strat_id': fields.many2one('agile.portfolio','Strat Id'),
}
portfolio_grid()
class assetid_name(osv.Model):
_name = 'assetid.name'
_rec_name = 'asst_id'
_columns = {
'asst_id' : fields.char('Asset_ID'),
}
assetid_name()
.xml code is here
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Portfolio View-->
<record id="agile_portfolio_form" model="ir.ui.view">
<field name="name">agile.portfolio.form</field>
<field name="model">agile.portfolio</field>
<field name="arch" type="xml">
<form string="AssetConfig">
<group>
<group>
<field name="name"/>
</group>
<group>
<field name="epic_owner"/>
</group>
</group>
<notebook>
<page string="Part Name">
<field name="strat_id1">
<form string="Part Name">
<group>
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</group>
</form>
<tree string="Part Name">
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
<record id="agile_portfolio_action" model="ir.actions.act_window">
<field name="name">AssetConfigs</field>
<field name="res_model">agile.portfolio</field>
<field name="view_type">form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Click to create a new portfolio</p>
</field>
</record>
<!--side menu's-->
<menuitem id="asset_config" name="AssetConfigs"/>
<menuitem id="portfolio_menu" name="AssetParts" parent="asset_config"/>
<menuitem id="portfolio_nxt_menu" name="AssetParts" parent="portfolio_menu" action="agile_portfolio_action"/>
</data>
</openerp>
openerp.py
{
'name': 'Agile',
'version':'1.0',
'description': """
Agile Methodology
- Portfolios
- Programs
- Projects
""",
'author': 'Suraj',
'depends': ['base_setup',],
'data': ['agile_view.xml',],
'installable': True,
'auto_install': False,
}
I think you have given the wrong model name in following field.
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID')
Here instead of "Agile.assetid.name" you have to give "assetid.name" if you want to manage M2O of last model "assetid.name". I think no model have capital letter.
I think this will resolve your issue.

How to pass input box value to a button action function in OpenERP?

There is an input box, labeled "Original", on the popup form, containing typed value '105-0045', picture attached. Button click action code is in the function action_replace(). What is the way to pass the input box value to the button function action_replace() when the "Replace" button is clicked?
Here is my XML code where the input box is defined:
<record id="replace_all_in_BOM_form" model="ir.ui.view">
<field name="name">replace.all.in.BOM.form</field>
<field name="model">product.template</field>
<field name="priority" eval="20"/>
<field name="type">form</field>
<field name="arch" type="xml">
<label class="text-inline" for="original_name" string="Original"
></label>
<input name="original_name" id="original_id" ></input>
<group>
<field name="default_code" string="Replacement" readonly="1"
invisible="0" />
<field name="uom_id" invisible="1" />
<field name="uom_po_id" invisible="1" />
<field name="type" invisible="1" />
<field name="categ_id" invisible="1" />
<field name="name" invisible="1" />
</group>
<button type="object" string="Replace" name="action_replace" />
</field>
</record>
<record id="action5" model="ir.actions.act_window">
<field name="name">Replace all in BOM</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="target">new</field>
<field name="view_id" ref="replace_all_in_BOM_form"/>
</record>
<record id="ir_BOM_structure5" model="ir.values">
<field eval="'client_action_multi'" name="key2"/>
<field eval="'product.template'" name="model"/>
<field name="name">Replace all in BOM</field>
<field eval="'ir.actions.act_window,'+str(action5)" name="value"/></record>
Here is the part of py code:
def default_get(self, cr, uid, fields, context=None):
product_obj = self.pool.get('product.template')
record_ids = context and context.get('active_ids', []) or []
res = {}
for product in product_obj.browse(cr, uid, record_ids, context=context):
if 'default_code' in fields:
#in 'default_code' is a field name of that pop-up window
res.update({'default_code': product.default_code, 'name': product.name, 'uom_id': product.uom_id.id,
'uom_po_id': product.uom_po_id.id, 'type': product.type, 'categ_id': product.categ_id.id })
return res
def action_replace(self, cr, uid, ids, context=None):
txt_value = ''
for record in self.browse(cr,uid,ids,context=context):
txt_value = record.original_id
return {
'type': 'ir.actions.act_window',
'res_model': 'product.template',
'name': _('Replace all in BOM'),
'res_id': ids[0],
'view_type': 'form',
'view_mode': 'form',
'view_id': 1212,
'target': 'new',
'nodestroy': True,
'context': context
}
Whenever a button is clicked, the default behaviour of the system is to save the data first and then to execute the button click function. So in the button click you will find 'ids' of current record. Following is the way where you will get the value of that textbox.
def action_replace(self,cr,uid,ids,context=None):
for record in self.browse(cr,uid,ids,context=context):
txt_value = record.original
<<your further code>>
return True