I am trying to pass the input values to action_button_confirm which is confirm onchange of sale order.
#http.route('/approve/<path:token>', type='http', auth='none')
def sale_order(self, token, **kwargs):
dbname = request.session._db
registry = openerp.modules.registry.Registry(dbname)
sale_id = http.request.env['sale.order'].sudo().search([('access_token', '=', token), ('state','=','draft')]).id
with registry.cursor() as cr:
http.request.env['sale.order'].action_button_confirm(sale_id,context=None)
I tried following scenarios
action_button_confirm(cr, openerp.SUPERUSER_ID, sale_id)
action_button_confirm(cr, uid, openerp.SUPERUSER_ID, sale_id)
action_button_confirm(cr, uid, openerp.SUPERUSER_ID, sale_id, contect=None)
The sale order confirm function is
def action_button_confirm(self, cr, uid, ids, context=None):
try below solution:
sale_id = http.request.env['sale.order'].sudo().search([('access_token', '=', token), ('state','=','draft')])
sale_id.action_button_confirm()
Related
Please help me to solve this problem,
I have a function which used to check validation terms of the input and I wants to call it inside the "create"function as a nested function. Once I call it in normal way it keeps giving me parameter mismatching error. Please help me.
Inside the create function I call it like this
def create(self, cr, uid, values, context=None):
#There are 219 lines in side the create function but I just showing you the invoke for this particular fucntion.
date_from = values['date_from']
date_to=values['date_to']
sub_nominee= values['sub_nominee']
self.onchange_sub_nominee(self, cr, uid, date_to, date_from,sub_nominee)
return super(hr_holidays, self).create(cr, uid, values, context=context)
Function is like this,
def onchange_sub_nominee(self, cr, uid,ids, date_to, date_from,sub_nominee):
#Employees data
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT).date()
to_dt=datetime.datetime.strptime(date_to, DATETIME_FORMAT).date()
sub_name=self.pool.get('hr.employee').browse(cr, uid, sub_nominee).name
hol_obj=self.pool.get('hr.holidays')
#if date_from==date_to:
hol_objs=hol_obj.search(cr, uid, [('employee_id','=',sub_nominee),('type','=','remove'),('state','not in',['draft','refuse'])])
#nominees data
if hol_objs:
for a in hol_obj.browse(cr, uid, hol_objs):
sub_from_dt = a.date_to
sub_to_dt=a.date_from
no_days=a.number_of_days_temp
sub_half_day=a.half_day
sub_half_day_sts=a.half_day_status
f_dt = datetime.datetime.strptime(sub_from_dt, DATETIME_FORMAT).date()
t_dt=datetime.datetime.strptime(sub_to_dt, DATETIME_FORMAT).date()
if ((from_dt==to_dt)and(to_dt==f_dt==t_dt)):
raise osv.except_osv(_('Warning!'),_(' %s already on leave on %s . Please nominate another person 111')%(sub_name,from_dt))
if ((from_dt!=to_dt)) and(no_days<=2):
while from_dt <= to_dt :
new_con=self.search(cr, uid, [('date_from', '<=', date_to), ('date_to', '>=', date_from), ('employee_id', '=', sub_nominee)])
if new_con:
raise osv.except_osv(_('Warning!'),_(' %s has/have already on leave(s) on that period . 55555Please nominate another person')%(sub_name))
from_dt = from_dt + datetime.timedelta(days=1)
if ((f_dt!=t_dt)):
while t_dt <= f_dt:
if (from_dt==t_dt)or(to_dt==t_dt):
raise osv.except_osv(_('Warning!'),_(' %s has/have already on leave(s) on that period . Please nominate another person 2222')%(sub_name))
t_dt=t_dt+datetime.timedelta(days=1)
return True
The error is self explanatory. There is a mismatch in the invoking parameters.
onchange_sub_nominee method accepts parameters
cr, uid, ids, date_to, date_from,sub_nominee
but was invoked as,
self.onchange_sub_nominee(self, cr, uid, date_to, date_from,sub_nominee)
You need to add the value of the parameter id after uid when calling it or remove that parameter from onchange_sub_nominee definition.
I am trying to change the value of my selection field using on_change. I have the code below.
.xml
<field name="product_id" on_change="onchange_partner_id_override(product_id, context)"
.py
class sale_order_line(osv.osv):
_inherit = "sale.order.line"
_columns = {
'product_id': fields.many2one('product.product', "Product"),
'price_select': fields.selection(SELECT_PRICE, "Unit Price"),
}
def product_id_change_override(self, cr, uid, ids, product, context=None):
result = []
product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product, context=context_partner)
global SELECT_PRICE
SELECT_PRICE = [
('sale_price', product_obj.list_price),
('dist_price', product_obj.distributor_price),
('emp_price', product_obj.employee_price),
]
# How could I change the value of my selection field 'price_select'
return {'value': result}
But i don't know the syntax on how to append this data on my selection field.
Could someone help me Please !
You need to override product_id_change method and specify the value of price_select field in value dict:
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
uom, qty_uos, uos, name, partner_id,
lang, update_tax, date_order, packaging, fiscal_position, flag, context)
res['value'].update({'price_select': 'emp_price'})
return res
I am trying to edit odoo inbuilt hr_attendance.py.My problem is following validation runs for particular record and not the entire recordset. In new api we use #api multi to execute a recordset.So how can I execute similarly using old api method of odoo 8
def _altern_si_so(self, cr, uid, ids, context=None):
""" Alternance sign_in/sign_out check.
Previous (if exists) must be of opposite action.
Next (if exists) must be of opposite action.
"""
for att in self.browse(cr, uid, ids, context=context):
# search and browse for first previous and first next records
prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name),
('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC')
next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name),
('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC')
prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
next_atts = self.browse(cr, uid, next_add_ids, context=context)
# check for alternance, return False if at least one condition is not satisfied
if prev_atts and prev_atts[0].action == att.action:
return self.write(cr, uid, ids, {'state': True})
if next_atts and next_atts[0].action == att.action: # next exists and is same action.
return self.write(cr, uid, ids, {'state': True})
if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in
return self.write(cr, uid, ids, {'state': True})
else:
return self.write(cr, uid, ids, {'state':False})
return True
_constraints = [
(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
I want to execute this method for checking validation for entire recordset not just particular record that is being edited or created.
How to make functional field editable in Openerp?
When we create
'capname': fields.function(
_convert_capital, string='Display Name', type='char', store=True
),
This will be displayed has read-only and we can't able to edit the text.
How we make this field has editable?
A computed field has a function that automatically calculates it's value on some source data.
It is possible to add it the inverse operation, updating the source data based on a value manually set on it, thus making it editable.
From the documentation:
to allow setting values on a computed field, use the inverse parameter. It is the name of a function reversing the computation and setting the relevant fields:
Example code:
document = fields.Char(compute='_get_document', inverse='_set_document')
def _get_document(self):
for record in self:
with open(record.get_document_path) as f:
record.document = f.read()
def _set_document(self):
for record in self:
if not record.document: continue
with open(record.get_document_path()) as f:
f.write(record.document)
You must add a inverse function to make the field editable. This parameter is called fnct_inv in OpenERP v7. An example:
def _get_test(self, cr, uid, ids, name, args=None, context=None):
result = dict.fromkeys(ids, False)
for line in self.browse(cr, uid, ids, context=context):
if line.test:
result[line.id] = line.test
return result
def _set_test(self, cr, uid, id, field_name, field_value, args=None, context=None):
obj = self.browse(cr, uid, id)
for record in obj:
if record.test != field_value:
# The record already exists
...
cr.execute(
'UPDATE your_table '
'SET test=%s '
'WHERE id=%s', (field_value, id)
)
else:
# It is a new record
# (or the value of the field was not modified)
return True
_columns = {
'test': fields.function(
string='String for testing',
fnct=_get_test,
fnct_inv=_set_test,
type='char',
size=50,
store=True,
),
}
I've been trying to copy over certain fields from the hr_expenses form into my custom module, purchase_orders.
The below method was written for me to do this in the extended hr_expenses.py file:
def po_generator(self, cr, uid, ids, arg, context=None):
res = {}
for expense in self.browse(cr, uid, ids, context=context):
expense_line = self.pool.get('hr.expense.line')
purchase_orders = self.pool.get('purchase.orders')
for line in expense.line_ids:
expense_line_record = expense_line.search(cr, uid, [('id', '=', line.id)], context=context)
# pdb.set_trace()
purchase_orders.create(cr, uid,
{
'submitted_employee_name':expense.employee_id,
'dateofexpense':expense_line.date_value,
'project_id_expense':expense_line.project_id,
'Description':expense_line.name,
'netamount':expense_line.product_exc_VAT,
'raised_employee_name':expense.employee_id,
'project_id_account_type':expense_line.project_id_account_type,
},
context
)
return res
However, when I tru to execute this piece of code, OpenERP gives me an 'AttributeError' with the traceback:
File
"/opt/openerp/custom_modules/legacy_expense_po/legacy_expense.py",
line 121, in po_generator
'dateofexpense':expense_line.date_value, AttributeError: 'hr.expense.line' object has no attribute 'date_value'
I'm presuming this has something to do with the line_ids field in the Expenses form. I'm trying to get each row in the line_ids and enter these as new records in the purchase_orders table.
Thanks.
#Sagar Mohan
You are doing vary basic mistake here.
You are already looping on browse record by saying statement
for line in expense.line_ids:
When you say expense.line_ids this will already pull all related o2m record you don't need to search again by writing statement expense_line_record = expense_line.search(cr, uid, [('id', '=', line.id)], context=context) and you must know that search in v7 return then only integer id of the matching ids not recordset or browse record.
Correct code is :
def po_generator(self, cr, uid, ids, arg, context=None):
res = {}
purchase_orders = self.pool.get('purchase.orders')
for expense in self.browse(cr, uid, ids, context=context):
expense_line = self.pool.get('hr.expense.line')
purchase_orders = self.pool.get('purchase.orders')
for line in expense.line_ids:
purchase_orders.create(cr, uid,
{
'submitted_employee_name':line.employee_id.name,
'dateofexpense': line.date_value,
'project_id_expense': line.project_id.id,
'Description': line.name,
'netamount': line.product_exc_VAT,
'raised_employee_name': expense.employee_id.name,
'project_id_account_type': line.project_id_account_type,
},
context
)
return res
This code might need correction based on your need but you see that line is direct browse variable so you just need to . and access the field.
and one more note here that you never use self.pool.get inside loop that make your code heavy.
Thanks