I have created a custom module in Openerp . In the form view i have put the one2many field to display the previous records .
The one2many field is on one model "sic_client_detail"
But am not able to display the data in one2many field . What extra thing needs to be done .
In Py file :
class si_client_details(osv.osv):
_name = 'si_client_details'
_columns = {
'name' : fields.char('Employee No.'),
'employee_id': fields.many2one('hr.employee', "Employee", required=True),
'company_id': fields.many2one('res.company', 'Previous Company'),
'project': fields.char('Project Name' , required=True),
'indate': fields.date("Start Date"),
'outdate': fields.date("End Date"),
'company_id1': fields.many2one('res.company', 'Current Company', required=True),
'indate1': fields.date("Start Date", required=True),
'pstatus': fields.selection([('bench', 'Bench'),('open', 'Not Started'),('progress', 'Project InProgress'),('close', 'Project Completed'),('abort', 'Project Aborted')], 'Project Status' , required=True),
'address_id': fields.many2one('res.partner', 'Working Address'),
'comment': fields.text('Remarks', size=64),
'current_datetime': fields.datetime('Current Date', size=64),
'employee_line': fields.one2many('si_client_details', 'si_client_id', 'Historical Entries', size=64),
'si_client_id':fields.many2one('si_client_details','Si Client Details'),
'state': fields.selection([('draft', 'New'),('cancelled', 'Refused'),('confirm', 'Waiting Approval'),('accepted', 'Approved'), ],
'Status', track_visibility='onchange')
In Form View i have:
<field name="employee_line" widget="one2many" colspan="4" nolabel="1" domain="[('state','=','draft')]"/>
Related
I'm Trying to show records based on the active user,
My task_submission.py
class TaskSubmission(models.Model):
_name = 'training_program_management.task_submission'
solution_description = fields.Html(string="Task submission's Description", required=True)
partner_id = fields.Many2one('res.partner', string='trainee: ',
default=lambda self: self.env.user.partner_id.id, readonly=True)
task_id = fields.Many2one('project.task', readonly=True, string="submitting Task :")
project_id = fields.Many2one(related="task_id.project_id", string="Practical work ", readonly=True)
In TreeView i need to show only task submissions with
Partner_id= current_user_id.partner_id
I tried this but it doesn't seem to be working:
<record model="ir.actions.server" id="mysub_task_action">
<field name="name">My Task submissions</field>
<field name='model_id' ref='training_program_management.task_submission'/>
<field name="state">code</field>
<field name="code">
action = {
'type': 'ir.actions.act_window',
'name': 'My task submissions',
'view_mode': 'tree',
'view_type': 'tree',
'view_id': env.ref("training_program_management.mysub_task_tree_view").id,
'context': '{ "tree_view_ref":"mysub_task_tree_view"}',
'res_model': 'training_program_management.task_submission',
'views': [(env.ref('training_program_management.mysub_task_tree_view').id, 'tree')],
'domain' : '[("partner_id", "=","user.id.id_partner.id")]',
}
</field>
</record>
Does anyone have an idea of how to do it ?
It doesn't work because you mustn't use quotes around user.id.id_partner.id in your domain : user is actually a python object you can use in domains.
'domain' : '[("partner_id", "=", user.partner_id.id)]',
Should work.
I'm trying to change the default value of some property fields such as: 'cost_method', 'product_type' and 'valuation' of the 'product' module but I can only change the non-property fields only.
What I tried:
- I created a new module and inherited the 'product.template' model and overridden the '_default' dictionary only but it didn't work.
I created new fields with the same name but of another type (selection) not property but neither did this work.
The code:
_name = "product.template"
_inherit = "product.template"
_columns = {
'cost_method': fields.selection([('average', 'Average Price'),('standard', 'Standard Price'), ('real', 'Real Price')])
,'type': fields.selection([('product', 'Stockable Product'),('consu', 'Consumable'),('service','Service')], 'Product Type', required=True, help="Consumable are product where you don't manage stock, a service is a non-material product provided by a company or an individual.")
,'company_id': fields.many2one('res.company', 'Company', required=False)
}
_defaults = {
'company_id': False
,'type' : 'product'
, 'cost_method': 'average'
, 'barcode':'555'
}
Use only _inherit="product.template". In your case you don't need the _name property.
Did you add your py. File to your __init__.py?
Did you set the correct dependencies in your __openerp__.py. In your case "product"?
Hope that helps you. Let me know.
EDIT:
I could reproduce your problem. My Code for testing
# -*- coding: utf-8 -*-
from openerp.osv import osv, fields
class product_template(osv.osv):
_name = "product.template"
_inherit = "product.template"
_columns = {
'cost_method': fields.selection([('average', 'Average Price'),('standard', 'Standard Price'),('real', 'Real Price')]),
'type': fields.selection([('product', 'Stockable Product'),('consu', 'Consumable'),('service','Service')],'Product Type', required=True, help="Consumable are product where you don't manage stock, a service is a non-material product provided by a company or an individual.") ,
'company_id': fields.many2one('res.company', 'Company', required=False)
}
_defaults = {
'company_id': False,
'type' : 'consu',
'cost_method': 'average',
'barcode':'555'
}
Here the type-field never had the consu value. In my case I could solve the problem by opening the menu Settings -> Technical Settings -> Actions -> User-defined Defaults. I deleted all entries where the name is type and modelname is product.template.
Now if I create a new product the default type is consu. Same behaviour with cost_method-field.
I Created a new module and inherited stock.picking module.In that added Accepted state between ready-to transfer and transfer state in warehouse. and a accept Button in header.
while clicking on accept button ,function is executing but state is not changing to accepted state.other functions of existing module are working correctly.
I added new accept selection field in existing module. i.e stock.picking
.py file
from openerp.osv import fields, osv
from openerp.exceptions import except_orm, Warning, ValidationError
import logging
class inventory_button_action(osv.osv):
_inherit = 'stock.picking'
def execute_accept_button(self, cr, uid, ids, context=None):
log = logging.getLogger(__name__)
log.info('######### Executed 11111 ########')
self.change_state_accept(cr, uid, ids, context=context)
def change_state_accept(self, cr, uid, ids, context=None):
log = logging.getLogger(__name__)
obj = self.pool.get('stock.picking')
obj.write(cr, uid, ids, {'state': 'accept'},context=context)
log.info('######### Executed 2222 ########')
xml file
<?xml version="1.0"?>
<openerp>
<data>
<record id="inventory_form_view" model="ir.ui.view">
<field name="name">inventory_status_form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//form/header/button[#name='do_enter_transfer_details']" position="before">
<button string="Accept" name="execute_accept_button" type="object" attrs="{'invisible':['|', ('state', 'in', ('draft','cancel','waiting','confirmed','partially_available','accept','done'))]}"/>
</xpath>
</field>
</record>
</data>
</openerp>
in stock.picking module
_columns = {
'name': fields.char('Reference', select=True, states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, copy=False),
'origin': fields.char('Source Document', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="Reference of the document", select=True),
'backorder_id': fields.many2one('stock.picking', 'Back Order of', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="If this shipment was split, then this field links to the shipment which contains the already processed part.", select=True, copy=False),
'note': fields.text('Notes'),
'move_type': fields.selection([('direct', 'Partial'), ('one', 'All at once')], 'Delivery Method', required=True, states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}, help="It specifies goods to be deliver partially or all at once"),
'state': fields.function(_state_get, type="selection", copy=False,
store={
'stock.picking': (lambda self, cr, uid, ids, ctx: ids, ['move_type'], 20),
'stock.move': (_get_pickings, ['state', 'picking_id', 'partially_available'], 20)},
selection=[
('draft', 'Draft'),
('cancel', 'Cancelled'),
('waiting', 'Waiting Another Operation'),
('confirmed', 'Waiting Availability'),
('partially_available', 'Partially Available'),
('assigned', 'Ready to Transfer'),('accept','Accepted'),
('done', 'Transferred'),
], string='Status', readonly=True, select=True, track_visibility='onchange')}
You do not need a browse record stock.picking to save a value.
When you write stok_obj.state = 'accept' you have just change instance value nothing will be saved in the database (available since odoo-8).
To change state to accept you can use write function:
openerp:
def execute_accept_button(self, cr, uid, ids, *args):
self.write(cr, uid, ids, {'state': 'accept'})
return True
Odoo:
#api.multi
def execute_accept_button(self):
self.write({'state': 'accept'})
return True
Try following:
def chnage_state_accept(self, cr, uid, ids, context=None):
self.write(cr,uid,ids,{'state':'accept'},context=context)
return <<return value if needed>>
Im trying to change the content of a many2one field when another field trigger onchange method.
Heres my py code:
class proevent(osv.osv):
_name = 'proevent.events'
_description = 'Events Module'
def onchange_client(self,cr,uid,ids, client_id,sale_orders_ids,context=None):
res={}
order_obj = self.pool.get('sale.order')
order_ids = order_obj.search(cr,uid, [('partner_id','=',client_id)])
logging.info('LIST OF SALE ORDERS OF SELECTED PARTNER')
logging.info(order_ids)
res['sale_orders_ids'] = order_ids
logging.info(res)
return {'value':res}
_columns = {
'eventdesc': fields.char('Evento', required=True),
'client_id': fields.many2one('res.partner', 'Cliente', required=True, change_default=True, select=True,track_visibility='always',domain=[('customer','=',True)]),
'sale_orders_ids': fields.many2one('sale.order','Lista'),
'eventaddress': fields.char('Direccion de Evento', required=True),
'description': fields.char('Descripcion del Evento', required=True),
'datein': fields.date('Fecha de Ingreso a Sistema', required=True, readonly=True),
'setupdatein': fields.datetime('Inicio de Montaje', required=True),
'setupdateout': fields.datetime('Fin de Montaje', required=True),
'eventdatein': fields.datetime('Inicio de Evento', required=True),
'eventdateout': fields.datetime('Fin de Evento', required=True),
'eventnotes': fields.char('Notas del Evento', required=True),
'readonlynote': fields.char('Nota'),
'partner_rtn': fields.related('partner_id','RTN',type="char",relation="res.partner",string="RTN",store=True,readonly=True),
}
proevent()
When I select a client_id which is filtered to only show customers,in triggers onchange method and then my onchange_client function.
My problem is I can't make my sale_orders_ids many2one field to show only the sale order ids from the selected partner,it show all the sale orders of the system.
How can I populate my sale_order_ids field?
def onchange_client(self,cr,uid,ids, client_id,sale_orders_ids,context=None):
res={}
order_obj = self.pool.get('sale.order')
order_ids = order_obj.search(cr,uid, [('partner_id','=',client_id)])
logging.info('LIST OF SALE ORDERS OF SELECTED PARTNER')
logging.info(order_ids)
return {'domain':{'sale_orders_ids':[('id','in',order_ids)]}}
you can do it with set domain on many2one field.
I hope this question makes sense. My goal is to display field as defined in name_get(). I have overridden name_get() function in mrp_bom class, code attached. However, I don't know which field will get return value from the function name_get(). Any insight is greatly appreciated!
class mrp_bom(osv.osv):
_inherit = 'mrp.bom'
_name = 'mrp.bom'
_columns = {
'x_nk_default_code': fields.related('product_id', 'default_code',
type='char', relation='product.product',
string='Part Number', store=True,
readonly=True),
'x_nk_class_desc': fields.related('product_id', 'categ_id', 'name',
type='char', string='Class Description',
store=True, readonly=True),
'x_nk_item_desc': fields.related('product_tmpl_id', 'name',
type='char', relation='product.template',
string='Item Description', store=True,
readonly=True),
'categ_id': fields.related('product_id', 'categ_id', type='integer',
relation='product.product', string='Categ_ID',
store=True, readonly=True),
'x_category_code': fields.related('product_id', 'categ_id',
'x_category_code', type='char', string='Class
Description', store=True, readonly=True),
}
def name_get(self, cr, user, ids, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
if not len(ids):
return []
def _name_get(d):
name = d.get('name','')
code = context.get('display_default_code', True) and
d.get('x_category_code',False) or False
if code:
name = '[%s] %s' % (code,name)
return (d['id'], name)
result = []
for product_category in self.browse(cr, user, ids, context=context):
mydict = {
'id': product_category.id,
'name': product_category.name,
'x_category_code':
product_category.x_category_code,
}
result.append(_name_get(mydict))
return result
The name_get method is used to display value of a record in a many2one field. For example, in a sale order line, if you select a product, the value displayed in the sale order line for the field 'product_id' must be the result of the 'name_get' on the product.product object.
There is no special field to display the result of name_get. If you need to put the result of name_get method in a field of a record, you should create with an attribute 'compute' : http://odoo-new-api-guide-line.readthedocs.org/en/latest/fields.html#computed-fields
You can find more information here : http://odoo-new-api-guide-line.readthedocs.org/en/latest/environment.html?highlight=name_get
I hope this help you.