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,
}
Related
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.
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
I have a form with a Many2many field and I'm showing it as a tree view:
By clicking on a record in the Many2many field mentioned above, the form of the corresponding model is lifted in a modal panel, as expected:
I can't find a way to click on a record of the Many2many field, instead of lifting a wizard, I will have the form view corresponding to the model of that Many2many field, without lifting a popup. In other words, this way:
Any suggestions?
You can write an action method on the model and extend the tree view showing this as button. This method should return an action which opens the record in a form view. That's the only "easy" way to do that, with the current Odoo framework.
A little example:
class MyModel(models.Model):
_name = 'my.model'
name = fields.Char()
class MyOtherModel(models.Model)
_name = 'my.other.model'
name = fields.Char
my_model_ids = fields.Many2many(
comodel_name='my.model')
#api.multi
def action_show_record(self):
# only use on singletons
self.ensure_one()
return {
'name': self.name,
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'my.model',
'context': self.env.context,
# don't open a popup
'target': 'current'
}
and the view of my.other.model
<record id="my_other_model_view_form" model="ir.ui.view">
<field name="name">my.other.model.view.form</field>
<field name="model">my.other.model</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name" />
<field name="my_model_ids">
<tree>
<field name="name" />
<button name="action_show_record" type="object"
string="Open" icon="an-font-awesome-icon" />
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
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.
In order to show this form view :
<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>
I created this action :
<record model="ir.actions.act_window" id="myprogram_action">
<field name="name">My Program</field>
<field name="res_model">res.partner</field>
<field name="form_view_id" ref="training_program_management.program_viewform"/>
<field name="domain">[('id','=',user.id.partner_id)]</field>
<field name="view_mode">form</field>
</record>
and this Menu :
<menuitem name="My Program" id="program_menu" sequence="5"
parent="training_program_management.menu" action="training_program_management.myprogram_action"/>
What I need is to show the record of res_partner corresponding to the current User, knowing that res.users contains a Many2one Field "Partner_id".
What do I need to do?
This is tested for odoo 8 but it can probably be adapted for odoo 10 or at least help you :
Change <record model="ir.actions.act_window" id="myprogram_action"> to <record model="ir.actions.server" id="myprogram_action">
Then add (yes, old API is on purpose, it doesn't work with the new API, for odoo 8 that is)
<field name='model_id' ref='base.model_res_partner'/>
<field name="code">
action = self._action_open_user_res_partner(cr, uid)
</field>
Create a model extending res.partner in your module, add (more old API ... also I didn't find a way to use ref())
#api.model
def _action_open_user_res_partner(self, cr, uid):
return {
'view_type': 'form',
'view_mode': 'form',
# Since this is a constant, you can use a global to hold the value for 'view_id'
'view_id': int(self.pool['ir.ui.view'].search(cr, uid,
[('name', '=', 'My Program')])[0]),
'res_model': 'res.partner',
'res_id': int(self.pool['res.users'].browse(cr, uid, [uid])[0].partner_id),
'type': 'ir.actions.act_window',
'context': {}
}
Adapting this to odoo 10 probably involves using the new API instead of the old one. This means self.pool should be self.env or env, and that you don't need cr and uid anymore. You can use user variable instead of uid in the function returning (well actually it could be used for odoo 8 too, but since uid is needed anyway...).
On the other hand, the documentation for odoo 10 about actions strongly suggests you'd still need to use the old API for this, except for model replacing self.
So you should first try something like this for odoo 10 :
<field name='model_id' ref='base.model_res_partner'/>
<field name="code">
action = model._action_open_user_res_partner(cr, uid)
</field>
The function in the model is still the same, since we still use the old API.
If it doesn't work, you should try with the new API (get rid of cr, uid)
The code bellow, worked perfectly for me, Thank you alot for your help:
<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',
'res_model': 'res.partner',
'nodestroy': 'true',
'res_id': int(env['res.users'].browse(env.user.partner_id.id)),
'views': [(False, 'form')],
'view_id': 'ref="training_program_management.program_viewform"',
}
</field>
</record>
Still have a small problem thou, i have two FormViews for res.partner, this line doesn't seem to show the desired View:
'view_id': 'ref="training_program_management.program_viewform"',
It shows me The First FormView That i've inherited.
My training_program_management.program_viewform :
<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>
What can i do to show this View Instead Of the inherited one ?