I have this field below
name = fields.Text("Input text here")
And I want to pass its value to the wizard when I click a button. Here's the code:
#api.multi
def open_wizard(self):
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'customer.wizard',
'target': 'new',
'type': 'ir.actions.act_window',
'context': {'current_id': self.id}
}
And here is my XML. But it still didn't work as I expected.
For the button:
<button name="open_wizard" string="Submit" type="object" class="oe_highlight" context="
{'name': name}"/>
For the wizard itself. I want the value to be on the 'Resi' field:
<record id="view_test_report_wizard" model="ir.ui.view">
<field name="name">Customer Wizard</field>
<field name="model">customer.wizard</field>
<field name="arch" type="xml">
<form string="Choose The Details">
<group>
<tree>
<group>
<field string="Resi" name="name" context="{'name' : name}"/>
<field name="tanggal"/>
<field name="kotaasal"/>
<field name="kotatujuan"/>
<field name="id_customer"/>
</group>
</tree>
</group>
<footer>
<button string="Back" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
Do you have any solution? Thank you
you can try this way
wiz = self.env['customer.wizard'].create({'name': self.name})
#api.multi
def open_wizard(self):
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'customer.wizard',
'res_id': wiz.id,
'target': 'new',
'type': 'ir.actions.act_window',
}
or you can pass the value in the context
'context': {
'default_name': self.name,'default_tanggal': self.tanggal
'default_kotaasal': self.kotaasal,'default_kotatujuan': self.kotatujuan
,'default_id_customer': self.id_customer.id
}
Just update the context on method open_wizard like the following:
'context': {'default_name': self.name}
That will (virtually) create the wizard with the value of self.name.
Related
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
So i made a menu that is calling a method that makes some logic and creates records in product.assortment.remove and after all record are created it returns a view. But my problem is that I get the view with 0 records.
My goal is that my method should return a view with all records created and a user can remove some records( with trash icon like in average tree view) how can i acheave that?
P.S.
actually i changed view to tree and <field name="model">assortment.product.removal.wiz</field> to product.assortment.remove and it returned me tree view with all records, but that view is without trash can icon so user can't delete records
class AssortmentProductRemoval(models.TransientModel):
_name = 'assortment.product.removal.wiz'
_description = "Wizard for removing assortment product"
prod_assort_rem_ids = fields.One2many(
'product.assortment.remove', 'product_id',
string='Product Assortmen Remove',)
#api.multi
def _check_assortment_items(self):
<-- some logic here -->
assort_rem_obj = self.env['product.assortment.remove']
vals = ({'qty_sold': qty,
'product_id': product.id,
'profit': profit})
assort_rem_obj.create(vals)
view = self.env.ref('config_hetlita.assortment_product_removal')
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'assortment.product.removal.wiz',
'views': [(view.id, 'form'), (False, 'tree')],
'res_id': self.id,
'target': 'new'
}
class ProductAssortmentRemove(models.Model):
_name = 'product.assortment.remove'
product_id = fields.Many2one(
'product.template', string='Product',
domain=[],
required=False)
turnover = fields.Float(string='Turnover', required=False)
profit = fields.Float(string='Profit', required=False)
qty_sold = fields.Float(string='Quantity sold', required=False)
<record model="ir.ui.view" id="assortment_product_removal">
<field name="name">view.name</field>
<field name="model">assortment.product.removal.wiz</field>
<field name="arch" type="xml">
<form string="Update Set">
<field name="prod_assort_rem_ids" >
<tree editable="bottom">
<field name="product_id"/>
<field name="turnover"/>
<field name="qty_sold"/>
</tree>
</field>
<footer>
<button string="Cancel" icon="gtk-cancel" special="cancel" />
or
<button name="action_save_sol" string="Save" type="object" icon="gtk-ok"/>
</footer>
</form>
</field>
</record>
<record id="action_test2" model="ir.actions.server">
<field name="name">Assortment product removal</field>
<field name="model_id" ref="model_assortment_product_removal_wiz"/>
<field name="state">code</field>
<field name="code">action = self._check_assortment_items(cr, uid, context.get('active_ids'), context=context)</field>
</record>
<menuitem id="your_menu_id12" action="action_test2" parent="base.menu_sale_config" name="Assort remove" sequence="1"/>
Make sure your user have delete access right and you can force the delete icon on the tree like this
<tree delete="1" >
And because you are showing you record in a wizard just show them in form view
# remove views key and use view_id
'view_id': view.id
I think you are missing the delete icon because odoo is showing the record in view mode not edit mode because you used views instead of view_id. Or your user don't have delete access right on the model.
I created Two form Views for res.partner module.
The first one is inherited, and the second one Showing only few fields :
<record model="ir.ui.view" id="program_viewform">
<field name="name">My Program</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<form>
<separator string="My Program " />
<field name="projects_ids" nolabel="True"/>
<separator string="submitted Tasks" />
<field name="submission_task_ids" nolabel="True"/>
</form>
</field>
</record>
And used this action :
<record model="ir.actions.server" id="myprogram_action">
<field name="name">My Program</field>
<field name='model_id' ref='base.model_res_partner'/>
<field name="state">code</field>
<field name="code">
action = {
'type': 'ir.actions.act_window',
'name': 'My Program',
'view_mode': 'form',
'view_type': 'form',
'view_id': 'ref="training_program_management.program_viewform"',
'context': '{ "form_view_ref":"program_viewform"}',
'res_model': 'res.partner',
'res_id': int(env['res.users'].browse(env.user.partner_id.id)),
'views': [(True, 'form')],
}
</field>
</record>
It works Pefectly right, with no errors, The problem is it shows the first ForView, and i need to show the view with the id: program_viewform.
I still have a bit confusion in ir.actions.server, and i don't understand the use of this line :
'views': [(True, 'form')],
And why this line doesn't show me the desired View ?
'view_id': 'ref="training_program_management.program_viewform"',
Any explanation would be helpful.
don't right the return directly in the server action create a method
that return the same dictionary, python code in XML is hard to read and write.
<field name="code">action = model.open_form_view()</field>
and in your model define this method:
#api.model
def open_form_view(self):
# FIRST GET THE ID OF THE VIEW
form_id = self.env.ref('training_program_management.program_viewform').id
# if you want to open the res partener related to the user
recor_id = self.env.user.partner_id.id
return {
'type': 'ir.actions.act_window',
'name': 'My Program',
'view_mode': 'form',
'view_type': 'form',
# form_id accept integer value.
# if you are using only one view
# no need to use views
'view_id': form_id,
'context': {},
'res_model': 'res.partner',
'res_id': record_id ,
# but if you are using more then one view
# you must use views to pass mutliple ids
#'views': [(form_id, 'form'), (tree_id, 'tree')],
# and to specify the search view use
# 'search_view_id': search_view_id,
}
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.
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