Cannot set invisible property on button with url widget in Odoo10 - odoo

I am trying to set up an attribute 'invisible' on button if the link is not given. But it returns me an error:
Uncaught Error: Unknown field link in domain [["link","=",false]]
I guess, the problem is because the field I am trying to refer to has widget "url".
The form view where the field 'link' is set.
<record id="documents_form" model="ir.ui.view">
<field name="model">documents.example</field>
...
<field name="link" widget="url" placeholder="e.g. www.example.com"/>
...
</record>
The tree view where it happens:
<record id="documents_tree" model="ir.ui.view">
<field name="model">documents.example</field>
<field name="arch" type="xml">
<tree string="Documents">
...
<button name="open_link" type="object" attrs="{'invisible': [('link', '=', False)]}"/>
...
</tree>
</field>
</record>
The class itself:
class Documents(models.Model):
...
_name = 'documents.example'
link = fields.Char("Link")
...
def open_link(self):
return {
'name': 'Go to website',
'res_model': 'ir.actions.act_url',
'type': 'ir.actions.act_url',
'target': 'new',
'url': self.link
}
What is the problem here?

You probably are not including the link field in your tree view. Add the link field to your tree view and make it invisible.
<field name="link" invisible="1"/>

Related

Odoo - How add a field to view from another wizard model?

I want the use a field from wizard to my form view.
Let me explain with code:
class CancelAppointmentWizard(models.Model):
_name = "cancel.appointment.wizard"
_description = "Cancel Appointment Wizard"
reason = fields.Text(string="Reason")
and i want the show this "reason" field inside of some form views.
<record id="view_hospital_appointment_form" model="ir.ui.view">
<field name="name">hospital.appointment.form</field>
<field name="model">hospital.appointment</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="reason"/>
</group>
</sheet>
</form>
</field>
</record>
but of course this give me error like
hospital.appointment don't have a field like reason.
How can show this field ?
I tried to make a dummy code, i hope i was able to explain my problem.
I assume the wizard is called from the view_hospital_appointment_form. And in the wizard view let say there is a button tag with name attribute, which is this attribute associated to python method in your wizard class.
Wizard view
<record id="view_cancel_appointment_wizard_form" model="ir.ui.view">
<field name="name">cancel.appointment.wizard.form</field>
<field name="model">cancel.appointment.wizard</field>
<field name="arch" type="xml">
<form>
…
…
<footer>
<button name="action_ok" string="Ok" type="object"/>
</footer>
</form>
</field>
</record>
Python method
def action_ok(self):
ids = self.env.context.get('active_ids')
hospital_appointment = self.env['hospital.appointment'].browse(ids)
hospital_appointment.reason = self.reason
return {'type': 'ir.actions.act_window_close'}

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

returning view with all records

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.

Show from Action Menu the Res_partner Form with partner information corresponding to the current User

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 ?

Odoo 9 yes/no pop-up box python

Odoo v9.
I would like to prompt the user with a yes/no option before certain python code is executed.
If this were in a button I could use the confirm="text?" attribute, however I do not want to trigger any database updates irrespective of the users answer to this particular prompt.
e.g. onchange event triggers yes/no box, which can then manipulate page, however the user still has to press "save" to keep any changes.
Is there any way of doing this using base odoo?
onchange events can't return a dialog because they were simply not built to do that https://www.odoo.com/forum/how-to/developers-13/what-should-onchange-methods-do-and-return-57760
You can use a wizard (it's not really a wizard it's just a form) and show it as a popup. our wizard model will be a Transient model, which would be discarded by odoo after a specified amount of time.
from openerp import fields, models, api
class test_model(models.Model):
_name = 'test.model'
name = fields.Char(string='Value')
#api.multi
def call_up_wizard(self):
return {
'name': 'Are you sure?',
'type': 'ir.actions.act_window',
'res_model': 'wizard',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
}
class wizard(models.TransientModel):
_name = 'wizard'
yes_no = fields.Char(default='Do you want to proceed?')
#api.multi
def yes(self):
pass
# sure continue!
#api.multi
def no(self):
pass # don't do anything stupid
This is how your view would look like
<record id="cashadvance_list" model="ir.ui.view">
<field name="name">Test Dialog</field>
<field name="model">test.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test Dialog" version="8.0">
<group>
<button class="oe_highlight" name="call_up_wizard" string="confirm" type="object" />
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="wizard_form">
<field name="name">wizard.form</field>
<field name="model">wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Confirm dialog">
<field name="yes_no" readonly="1" />
<footer>
<button class="oe_highlight" name="yes" string="Yes" />
<button class="oe_highlight" name="no" string="No" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_test">
<field name="name">Cash advance list</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">test.model</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
It's empty, create something
</p>
</field>
</record>
In our test_model view we have a button that's shows the wizard as a popup, and then in the wizard buttons are handled by the yes and no methods respectively, this gives you better control over the buttons as you know have separate methods controlling the two buttons you have on the form.
I just put this answer, for anyone who happens to stumble on this thread and wants to know how to create a popup from a button.