I like to generate a report to xls/xlsx file. I want to get all the product list on another Model to a TransientModel. ( I do my research but without someone explaining it to me I am not able to get the whole picture. )
aging_inventory_report.py
***aging_inventory_report.py***
from time import strftime, gmtime
from odoo import models, fields, api
from report_xlsx.report.report_xlsx import ReportXlsx
class AgingInventoryReport(models.TransientModel):
_name = 'aging.inventory.report'
_inherit = 'product.template'
_description = 'Aging of Inventory Report'
***from here, these are the codes that I get from searching over internet***
def print_xls_report(self, cr, uid, ids, context=None):
data = self.read(cr, uid, ids)[0]
return {'type': 'ir.actions.report.xml',
'report_name': 'dealer_stock_aging_report.report_name.xlsx',
'datas': data
}
class ClassABCD(ReportXlsx):
def generate_xlsx_report(self, workbook, data, lines):
current_date = strftime("%Y-%m-%d", gmtime())
logged_users = self.env['res.users'].search([('id', '=', data['create_uid'][0])])
sheet = workbook.add_worksheet()
# add the rest of the report code here
ClassABCD('report.dealer_stock_aging_report.report_name.xlsx', 'product.template')
*** I don't under stand the code but it successfully integrate into my model.***
XML
aging_inventory_report.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_aging_inventory_report" model="ir.ui.view">
<field name="name">Aging of Inventory</field>
<field name="model">aging.inventory.report</field>
<field name="arch" type="xml">
<form string="Aging Inventory">
<group>
<p>
Retrieve list of Aging Inventory.
</p>
</group>
<footer>
<button name="print_xls_report" string="Save as XLS" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>
</odoo>
view_aging_inventory_report.xml
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="action_view_aging_inventory_report" model="ir.actions.act_window">
<field name="name">Retrieve Aging Inventory Report</field>
<field name="res_model">aging.inventory.report</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_aging_inventory_report"/>
<field name="target">new</field>
</record>
<menuitem id="action_menu_aging_inventory_report"
name="Aging Inventory"
action="action_view_aging_inventory_report"
parent="dealer_inventory_cost.inventory_cost"
sequence="2"/>
</odoo>
Hoping someone could help me on this. Thank you. Id something is not clear please let me know.
I have simple database which has 3 models as follows
1- camps (to store Camps master data)
2- players (to store players master data)
3- players_camps (to store camps each player has attended)
the code for all models as follows:
class Camps(Model):
_name = 'camps'
name = Char('Name')
organizer = Char()
date_from = Date('From date')
date_to = Date('To date')
place = Char()
supervisor = Char()
notes = Text()
class players(Model):
_name = 'player'
name = Char()
camps = One2many('player_camps', 'player')
class player_camps(Model):
_name = 'player_camps'
camps = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
organizer = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
place = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
date_from = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
date_to = Many2one('camps', on_delete='CASCADE', on_update='CASCADE')
result = Integer(default=0)
when I display players camps (using One2many widget in the view ) I can see only the camp name but the other data
like organizer or place (which are stored in master model of camps) not shown
how can I show this data in the tree view of the players camps view ?
Edit: here is view file for players
Note: I have removed some fields from players view and its model to make the code shorter
<openerp>
<data>
<!--Form view -->
<record id="Player_form_view" model="ir.ui.view">
<field name="model">player</field>
<field name="arch" type="xml">
<form>
<notebook>
<page name="basic_data" string="Basic Data">
<group>
<field name="name"/>
</group>
</page>
<page name="camps" string="Camps">
<field name="camps">
<tree>
<field name="camp"/>
<field name="instructor"/>
<field name="organizer"/>
<field name="place"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="result"/>
<field name="notes"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
</data>
</openerp>
Please remove widget from one2many list and in <tree> tag declared field as many as you want to show.
Try with following code:
<openerp>
<data>
<!--Form view -->
<record id="player_form_view" model="ir.ui.view">
<field name="name">player.form.view</field>
<field name="model">spogaze.player</field>
<field name="arch" type="xml">
<form>
<notebook>
<page name="basic_data" string="Basic Data">
<group>
<field name="name"/>
</group>
</page>
<page name="exams" string="Exams">
<field name="exams">
<tree string="Exam" editable="bottom">
<field name="camp"/>
<field name="instructor"/>
<field name="organizer"/>
<field name="place"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="result"/>
<field name="notes"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
</data>
</openerp>
The following code is calendar.event inherited module so here I will store some inspection and all. Here relation is working fine.
from openerp.osv import fields, osv
from openerp import api
class calendar_event(osv.osv):
_inherit = "calendar.event"
STATE_SELECTION = [
('1', 'Corrective'),
('2', 'Preventive'),
('3', 'Predictive'),
]
SD_SELECTION = [
('Shut Down Required', 'Shut Down Required'),
('Shut Down Not Required', 'Shut Down Not Required'),
]
_columns = {
'number' : fields.char('Calendar Inspection ID',readonly=1),
'tags' : fields.selection(STATE_SELECTION, 'Tags',),
'user_id': fields.many2one('res.users','res_users_rel','Assigned', track_visibility='onchange',),
'sht_down': fields.boolean('Shut Down'),
'company_id11': fields.many2one('res.company', 'Substation', required=True),
#'place' : fields.many2one('asset.parentlocation','Substation Location',),
'assetmodelid_add' : fields.many2one('agile.portfolio1','Asset Model Code',),
'folio_num1' : fields.many2one('asset.asset','Folio Num',),
'inspection_name' : fields.many2many('asset1.inspection','asset1_inspection_rel','super_id','asset1_inspection_id','Inspection Type'),
'insp_rslt' : fields.one2many('feedback.tree','insp_rsltts','Inspection Result',),
'same_as':fields.boolean(),
}
_defaults = {
'number' : lambda self,cr,uid,context={}:self.pool.get('ir.sequence').get(cr,uid,'calendar.event'),
'sht_down': False,
}
def onchange_same_as(self,cr, uid, ids,same_as_above,inspec_type,context=None):
if same_as:
return {'value':{'shutdown':frequency,}}
return {'value':{}}
class feedback_tree(osv.Model):
_name = 'feedback.tree'
STATUS = [
('done', 'Completed'),
('notdone', 'Not-Completed'),
]
_columns = {
'folionum' : fields.many2one('calendar.event','Task Name',),
#'folio_number' : fields.many2one('asset.asset','Folio number',),
'inspec_type' : fields.char('Inspection Type',),
'insp_msr1' : fields.many2one('results.measure','Attributes',),
'valuess' : fields.char('Values'),
'status' : fields.selection(STATUS,'Status'),
'insp_rsltts': fields.many2one('feedback.form','Result Id'),
}
The follwoing code is .xml file for above inherited class
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Form & Tree View for Visitor Register -->
<record model="ir.ui.view" id="inherit_calaner_event">
<field name="name">calender.event.inherit</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/div[#class='oe_title']" position="after">
<group>
<!-- <field name="number"/>-->
<field name="company_id11"/>
<!--<field name="asset_catg_id"/>
<field name="area_id" widget="selection"/>-->
<field name="assetmodelid_add" />
<field name="folio_num1" domain="[('assetmodelid_add', '=', assetmodelid_add)]"/>
<field name="inspection_name" domain="[('assetmodelid_add', '=', assetmodelid_add)]"/>
<field name="sht_down"/>
</group>
</xpath>
<xpath expr="//form/sheet/notebook/page/group/group/field[#name='location']" position="after">
<group>
</group>
</xpath>
<xpath expr="//form/sheet/notebook/page/group/group/field[#name='categ_ids']" position="replace">
<field name="tags"/></xpath>
<xpath expr="//form/sheet/div/label[#string='Attendees']" position="replace">
<label string="Attendees" class="oe_edit_only"/></xpath>
<xpath expr="//form/sheet/div/h2" position="replace">
<field name="user_id"/></xpath>
<xpath expr="//form/sheet/notebook/page[#string='Meeting Details']" position="after">
<page string="Feedback">
<field name="insp_rslt" >
<tree string="Feedback" editable="bottom" >
<field name="folionum" />
<field name="insp_msr1"/>
<field name="valuess"/>
<field name="status"/></tree></field>
</page>
</xpath>
</field>
</record>
<record id="calendar_view_calendar_event_search" model="ir.ui.view">
<field name="name">calender.event.view</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_search"/>
<field name="arch" type="xml">
<xpath expr="//search/filter[#name='message_unread']" position="after">
<filter string="Shut Down" name="sht_down" domain="[('sht_down','=',True)]"/>
<filter string="No Shut Down" name="sht_down" domain="[('sht_down','=',False)]"/></xpath>
</field>
</record>
</data>
</openerp>
My Requirement is First I will select inspection_name field in calender.evnt class. In feedback.tree I have one column inspc_type this field has to give only same list as many2one of inspection_name which assigned for this instance.
Example: inspction_name has A,B,C
in feedback.tree for inspec_type should get only A,B,C not all inspection_name which stored before this record.
-----------------Edited------------------------------
I have calendar.event.py
'inspection_name' : fields.many2many('asset1.inspection','asset1_inspection_rel','super_id','asset1_inspection_id','Inspection Type'),
.xml file of calendar.event.py
<field name="assetmodelid_add" />
<field name="folio_num1" domain="[('assetmodelid_add', '=', assetmodelid_add)]"/>
<field name="inspection_name" domain="[('assetmodelid_add', '=', assetmodelid_add)]"/>
I want same filter in feedback.tree. When I do domain filter its showing assetmodelid_add doesn't exist. ya because in feedback.tree we don't have this field so how to crack this
'inspec_type': fields.char('Inspection Type',),
field has to be done domain filter for this class for 'inspec_type' field
i make a simple wizard in odoo and i want to show the wizard but, my model can't found of my view . what wrong with my simple code?
This my wizard
class RequestReceiveWizard(models.TransientModel):
_name ='estate.nursery.requestreceivewizard'
# def _default_session(self):
# return self.env['estate.nursery.requestline'].browse(self._context.get('request_id'))
name=fields.Char("Wizard name")
request_id=fields.Many2one('estate.nursery.request')
requestline_ids = fields.Many2many("estate.nursery.requestline")
And this my view :
<!--request Wizard -->
<record model="ir.ui.view" id="request_view_wizard">
<field name="name">Request receive wizard</field>
<field name="model">estate.nursery.requestreceivewizard</field>
<field name="arch" type="xml">
<form string="Wizard For Request Received">
<group collspan="2" col="2">
<field name="name"/>
<field name="requestline_ids"/>
</group>
<footer>
<button name="Apply" type="Action" string="Apply" >Apply</button>
<button special="cancel" string="Cancel">Cancel</button>
</footer>
</form>
</field>
</record>
<act_window id="received_request_wizard" name="Request Wizard"
src_model="estate.nursery.request"
res_model="estate.nursery.requestreceivewizard"
view_mode="form"
target="new"
multi="True" key2="client_action_multi"/>
What wrong with my simple code? And this my error
Model not found: estate.nursery.requestreceivewizard
act_window replace to this record and try this code:
<record id="received_request_wizard" model="ir.actions.act_window">
<field name="name">estate.nursery.request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">estate.nursery.request</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="request_view_wizard"/>
<field name="target">new</field>
</record>
May be It's work for you...
i created a wizard and now its giving me the above error , it took me ages but couldn't sorted it , between am doing wizard for the first time in Openerp . please help thanks in advance . here is my code
class test_wizard(osv.osv_memory):
_name="test.wizard"
_description="will generate dynamic views, that's all"
_columns={
'age_text': fields.text('text age'),
}
def next(self,cr,uid,ids,contet=None):
test_obj=self.pool.get('test.chbc')
for wiz in self.browse(cr,uid,ids):
if wiz.age_text <=5:
raise osv.except_osv('user error, please slect something , know what')
limit= datetime.date.today()-datetime.timedelta(days=wiz.age_text)
ids_to_del=test_obj.search(cr,uid,[('create_date','<',
limit.striftime('%y-%m-%d 00:00:00'))],context=context)
test_obj.unlink(cr,uid,ids_to_del)
return{}
test_wizard()
here is my xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="test_wizard" model="ir.ui.view">
<field name="name">test.wizard.form</field>
<field name="model">test.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Test wizard ">
<label colspan="4" string="select age please , am in a hurry "/>
<field name="age_text" string="Age(days)"/>
<group col="4" colspan="4">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="next" string="Next" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_test_wizard" model="ir.actions.act_window">
<field name="name">Next</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">test.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
Change you model name mean give the name of the class where you want to put it
<field name="model">test.wizard</field>