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
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.
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,
}
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 ?
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.