How to upload images in tree view and display it in the tree or list view in Openerp 7 or Odoo - odoo

I have used the below code and on clicking on save. It saves the file but on clicking on the saved file. It is downloading it with a bin file format.
I have 2 doubts:
How do I download it using the same filename and extension that was uploaded.
How can I view all the images in the tree view from where it was uploaded. Using widget="image" does not work.
The openerp.py file:
{
'name' : 'Vyas File Upload Demo',
'version' : '0.1',
'category' : 'Demo',
'description' :
"""
Module to test the working of File upload and download in Openerp 7
""",
'author' : 'Vyas Senthil',
'license' : 'AGPL-3',
'depends' : [],
'init_xml' : [],
'demo_xml' : [],
'update_xml' : ['file_upload_demo_view.xml'],
'active': False,
'installable': True,
}
file upload demo.py [Python file]:
from osv import osv,fields
from datetime import date,datetime
from openerp import netsvc
from openerp import SUPERUSER_ID
from openerp.tools.translate import _
from operator import itemgetter
import base64
import time
import re
import psycopg2 as psy
import sys
import pprint # To print python objects in a readable format , use "pprint.pprint(obj or dictionary)".
import pdb # To debug python files. Use pdb.set_trace()
class manage_inspection(osv.osv):
''' Inspection module'''
_name = 'manage.inspection'
_columns = {
'name': fields.char('Inspection Number',required=True), # Inspection Number
'file_upload_demo_grid': fields.one2many('file.upload.demo','manage_inspection_id', 'File upload Grid'),
}
class file_upload_demo(osv.osv):
#class to maintain plant type
_name = 'file.upload.demo'
def _get_contract_file_name(self, cr, uid, ids, field_name, arg, context=None):
''' To set the name_filename field'''
result = {}
for product_data in self.browse(cr, uid, ids, context=context):
result[product_data.id] = product_data['file_path']
return result
return result
_columns = {
'image_upload': fields.binary(string='Image Upload new'),
'file_path': fields.char('File Name and Extension', size=128),
'name_filename':fields.function(_get_contract_file_name, type="char", size=255, method=True, string="File Name"),
'manage_inspection_id': fields.many2one('manage.inspection','Manage Inspection Id'), # Connection to Parent form.
}
file_upload_demo()
file_upload_demo_view.xml [XML file]:
<?xml version="1.0" ?>
<openerp>
<data>
<!-- Top Menu -->
<menuitem name="Vyas File Upload Demo"
id="file_upload_demo_top_menu"
sequence="32"/>
<!-- Side Menu Heading -->
<menuitem name="File Upload Demo"
id="file_upload_demo_side_heading"
parent="file_upload_demo_top_menu"
sequence="1"/>
<!-- inspection form view -->
<record model="ir.ui.view" id="view_file_upload_demo_form">
<field name="name">manage.inspection.form</field>
<field name="model">manage.inspection</field>
<field name="arch" type="xml">
<form string="Manage Inspection" version="7.0">
<!-- File Upload method -->
<field name="name" placeholder="Inspection Number" style="width:30%%" />
<!-- Grid - Upload Photos -->
<field name="file_upload_demo_grid" />
</form>
</field>
</record>
<!-- file_upload_demo tree view -->
<record model="ir.ui.view" id="view_file_upload_demo_tree">
<field name="name">file.upload.demo.tree</field>
<field name="model">file.upload.demo</field>
<field name="arch" type="xml">
<tree string="file upload demo" editable="top">
<!-- File Upload method -->
<field name="file_path" />
<field name="image_upload" filename="file_path" />
</tree>
</field>
</record>
<!-- action menu -->
<record model="ir.actions.act_window" id="action_upload_files_demo">
<field name="name">Inspection </field> <!-- view label -->
<field name="res_model">manage.inspection</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<!-- Side menu to open Manage Sales Invoice -->
<menuitem
name="Upload Files Demo"
id="upload_file_demo"
parent="file_upload_demo_side_heading"
sequence="3"
action="action_upload_files_demo"/>
</data>
</openerp>

look for Document button in project module this is allow you to attach multiple attachment and view them it tree , view the most beautiful thing that is preserve your attachment name and extension (try to do like it )
Note:
this attachment can be image or any type of attachment

Related

Display a field in the homepage odoo

I have created a module in odoo with a model called "product" and a string field called "formelab" , I want to display this "formelab" field just under the price on the product sheet.
I want to display "ABCCCC" on the PROD sheet under "$1.00"
that's the product_template.xml in the views folder
``
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="formelab_ref_id_form" model="ir.ui.view">
<field name="name">access.product.view.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='type']" position="after">
<field name="formelab_ref"/>
</xpath>
</field>
</record>
</odoo>
and that's the product.py in the models folder
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class product(models.Model):
_inherit = 'product.template'
formelab_ref = fields.Char("Formelab")
``
You need to alter the products_item template.
The following code add the formelab_ref value after the priceCurrency span:
<template inherit_id="website_sale.products_item" id="daz">
<xpath expr="//span[#itemprop='priceCurrency']" position="after">
<span t-field="product.formelab_ref"/>
</xpath>
</template>

Odoo 13 error in xml file while adding fields in custom module

I am getting this error while upgrading my custom module in odoo13 while upgrading it , the error is within this xml file.i have added somoe fields in xml file then it showing me this erro
error :
Odoo Server Error
Traceback (most recent call last):
File "/odoo/odoo-server/odoo/addons/base/models/ir_ui_view.py", line 392, in _check_xml
self.postprocess_and_fields(view.model, view_doc, view.id)
File "/odoo/odoo-server/odoo/addons/base/models/ir_ui_view.py", line 964, in postprocess_and_fields
self.raise_view_error(message, view_id)
File "/odoo/odoo-server/odoo/addons/base/models/ir_ui_view.py", line 592, in raise_view_error
raise ValueError(message)
ValueError: Field state does not exist
Error context:
View view.demo.form
[view_id: 1710, xml_id: gunalan_demo.request_form, model: car.request, parent_id: n/a]
models.py:
# -*- coding: utf-8 -*-
from odoo import models, fields, api , _
class gunalan_demo(models.Model):
_name = 'car.request' #Tables in DB =>car_request
_description = 'demo module'
name = fields.Char(string="Request_demo",required = True ,)
date_from = fields.Datetime(string='starting date',default=fields.Datetime.now(),)
date_to = fields.Datetime(string='Ending date',required=False,)
emplyoee_id= fields.Many2one(comodel_name="hr.employee", string="Emplyoee ", required=True,)
car_id = fields.Many2one(comodel_name="fleet.vehicle", string="Car ", required=True,)
state = fields.Selection(string="Status", selection=[('draft', 'Draft'), ('confirm', 'Confirm'),('validate','Validate'),('refuse','Refuse')('approved','Approved'),], default="draft", )
views.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id ="request_form" model ="ir.ui.view">
<field name="name">view.demo.form</field>
<field name="model">car.request</field>
<field name="arch" type="xml">
<form string ="Car Request Form">
<header>
<!--<button name="" string="" class="oe_highlight" states="" type=""/>-->
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate,refuse,approved"/>
</header>
<sheet>
<div class="oe_title">
<label for="name" class="oe_title_only"/>
<h1>
<field name="name" placeholder="Request Demo"/>
</h1>
</div>
<group>
<group>
<field name="date_from"/>
<field name="date_to"/>
</group>
<group>
<field name="emplyoee_id"/>
<field name="car_id"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id='request_tree' model='ir.ui.view' >
<field name='name'>view.demo.tree</field>
<field name='model'>car.request</field>
<field name='arch' type='xml'>
<tree string='Car Request Tree'>
<field name="name"/>
<field name="emplyoee_id"/>
<field name="car_id"/>
<field name="date_from"/>
<field name="date_to"/>
</tree>
</field>
</record>
<record id="action_request_views" model="ir.actions.act_window">
<field name="name">Car Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">car.request</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Car Request
</p><p>
Click here to add
</p>
</field>
</record>
<!-- This Menu Item will appear in the Upper bar, That's why It needs NO parent or action -->
<menuitem id="menu_car_request_root" name="Car Request" sequence="10"/>
<menuitem id="menu_car_request_categ" name="Car Request" parent="menu_car_request_root" sequence="1"/>
<menuitem id="menu_car_request" name="Car Request" parent="menu_car_request_categ" action="action_request_views" sequence="1"/>
Make sure you have added your model.py file in init.py file. If you have added model.py inside model folder, then make sure model is given in init.py file.

Odoo statusbar widget for project.project

i'm trying to add a field to define statuses of project.project like:
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class Project(models.Model):
_inherit = 'project.project'
_name = 'project.project'
state = fields.Selection(
[('open', 'Open'), ('closed', 'Closed'), ('sleep', 'Sleep')],
string='Status',
default='open'
)
Add added to the view in a heritage:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="edit_project" model="ir.ui.view">
<field name="name">project.project.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<field name="state" widget="statusbar" statusbar_visible="open,closed,sleep" />
</xpath>
</field>
</record>
</odoo>
But the field is displayed like a span in the header.
I tried everything described in the documentation and in base of other usages but with this in particular is not working and i don't know why. Please help!
Well, after trying everything for some ultra strange reason it work with no change.

Odoo - Override default company view

I am using odoo 10e. I want to change companies form and tree view. So i was following this tutorial
Help
and this is what i tried but its not working
<odoo>
<data>
<record model="ir.ui.view" id="view_crm_lead_form_inherited">
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form" />
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="string">Custodian Name</attribute>
</field>
</field>
</record>
</data>
</odoo>
I see that company model have a field nameand i am trying to override default label of name fields.
Edit
__manifest__.py
# -*- coding: utf-8 -*-
{
'name': "Test",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "Ancient",
'website': "http://www.google.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Accounting',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base', 'mail'],
# always loaded
'data': [
'security/ir.model.access.csv',
'security/amgl_security.xml',
'views/views.xml',
'views/customer.xml',
'views/dashboard.xml',
'views/products.xml',
'views/order.xml',
'views/order_line.xml',
'views/metal_movement.xml',
'views/possible_solutions.xml',
'views/possible_reasons.xml',
'views/pending_accounts.xml',
'views/dealer.xml',
'emailTemplates/mmr_create_mail.xml',
'emailTemplates/reject_mmr_email.xml',
'emailTemplates/mmr_approval_complete.xml',
'emailTemplates/mmr_approve_reject_button.xml',
'report/metal_movement_template.xml',
'report/metal_movement_view.xml',
'views/res_company.xml'
],
'qweb': [
"views/colspan.xml",
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
'demo/customer_view.xml'
]
}
Here the important part of the origin view:
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" class="oe_inline"/>
</h1>
<label for="rml_header1" class="oe_edit_only"/>
<h3>
<field name="rml_header1" placeholder="e.g. Global Business Solutions"/>
</h3>
</div>
You have to change the label, because the field label, which you try to override, is never used.
Following should work:
<label for="name" position="attributes">
<attribute name="string">Custodian Name</attribute>
<attribute name="for" />
</label>

Tree view showing extra empty fields

I have created a custom module, in my tree view, I will always have only 1 row data. But in my tree view it shows extra empty rows. how can I remove those unwanted empty rows?
My view code:
<record model="ir.ui.view" id="ctimesheet.list">
<field name="name">ctimesheet list</field>
<field name="model">time.recorder</field>
<field name="arch" type="xml">
<tree string="TIME SHEET" create="false">
<field name="total_time"/>
<field name="month_time"/>
<field name="yesterday_time"/>
<field name="week_time"/>
<field name="notsubmitted_time"/>
<field name="user_id" invisible="1"/>
</tree>
</field>
</record>
just go to path: Odoo 10.0\server\odoo\addons\web\static\src\js\views and edit file list_view.js line 1115
and change
this.pad_table_to(4);
To
this.pad_table_to(1);
updating javascript by editing odoo code is very bad you shoud use include to override
the code:
Create a new module and create a javascript file:
/your_addon_name/static/src/js/list_view.js
in you javascript file override the render method like this:
odoo.define('you_module_name.ListView', function (require) {
"use strict";
// First retrieve the veiw from view_registry
ListView = core.view_registry.get('list');
// now use include to override the render method
ListView.include({
render: function () {
// call super method first
this._super();
// then override what you need
// and best thing here is that you can dor this for
// your model only
if (this.model == 'addon_name.model_name'){
this.pad_table_to(1);
}
}
});
}
of curse just writing javascript will not do the trick we should put ower java script file to backends_asset template
to be loaded in odoo backend.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend_custom_id" name="list_view assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/your_addon_name/static/src/js/list_view.js"></script>
</xpath>
</template>
</odoo>
don't forget to put the xml file to odoo manifest hope this helps you and everyone else