how to show the error message "The room was already booked" . i want to check by ** room_id,** start** , how it is possible?
py file
_columns = {
'room_id' : fields.many2one('room.management', string="Room Booking"),
'duration': fields.integer('Duration'),
'reason': fields.char('Reason',requierd=True ,help="short deatails about booking"),
'start': fields.datetime('Start At',requierd=True),
'end': fields.datetime('End At',requierd=True),
}
You can use a constrains method decorator:
#api.one
#api.constrains('start', 'end', 'room_id')
def _check_room_overlap(self):
overlaping_bookings = self.search_count([
('room_id', '=', self.room_id.id),
('start', '<', self.end),
('end', '>', self.start),
])
if overlaping_bookings:
raise exceptions.ValidationError("The room was already booked")
Related
enter image description here
This my code and i don't know why this error happen.
#api.model
def update_prices_in_mitra(self):
self.ensure_one()
select_hargamitra = self.env['isd.res.partner.price_list'].search(
[('partner_id', '=', self.mitra_id.id)])
cek = []
# self.task_orderlines = [(5, 0, 0)]
for cek in select_hargamitra.price_list:
if (select_hargamitra and (len(select_hargamitra.price_list) > 0)):
for x in self.task_orderlines:
if cek.product_id.id == self.product_id.id:
x.write({'mitra_price': cek.price_amount,
'isd_mitra_status' : True})
Try this because there might be multiple record in a page i.e. tree view
#api.model
def update_prices_in_mitra(self):
for rec in self:
select_hargamitra = self.env['isd.res.partner.price_list'].search([('partner_id', '=', rec.mitra_id.id)])
cek = []
for cek in select_hargamitra.price_list:
if (select_hargamitra and (len(select_hargamitra.price_list) > 0)):
for x in rec.task_orderlines:
if cek.product_id.id == rec.product_id.id:
x.write({'mitra_price': cek.price_amount,
'isd_mitra_status' : True})
I am trying to construct an Odoo domain query with a logic of
(Condition 1) AND (Condition 2 OR Condition3)
This is the code I've written:
moves = self.env['account.move'].search(
[(
"&",
('sftp_uploaded', '=', False),
"|",
('move_type', 'in', ['entry']),
('move_type', 'in', ['out_receipt']),
)], limit=200)
Running this returns a strange error
ValueError: <class 'TypeError'>: "unhashable type: 'list'" while
evaluating 'model._sftp_cron_action()'
In the same function the following code works fine
moves = self.env['account.move'].search(
[(
'move_type', 'in', ['out_invoice']),
('sftp_uploaded', '=', False
)], limit=20)
You have one extra pair of parentheses.
moves = self.env['account.move'].search(
[
"&",
('sftp_uploaded', '=', False),
"|",
('move_type', 'in', ['entry']),
('move_type', 'in', ['out_receipt']),
], limit=200)
I have the following code to replace one term with another, this only works if the value exists in the pandas dataframe, I assume I need to wrap gdf[montype] = gdf[montype].replace(dict(montype), regex=True) in an if statement? How would I do this, or is there a better way?
montype = [
['HIS_COP_', ''],
['_Ply', ''],
['_Pt',''],
['BURIAL','burial'],
['CUT', 'CUT'],
['MODERN', 'MODERN'],
['NATURAL', 'NATURAL'],
['STRUCTURE', 'STRUCTURE'],
['SURFACE', 'SURFACE'],
['TREETHROW', 'natural feature'],
['FURROW', 'FURROW'],
['FIELD_DRAIN', 'FIELD_DRAIN'],
['DEPOSIT_FILL', 'DEPOSIT_FILL'],
['POSTHOLE', ''],
['TIMBER', ''],
['', '']
]
gdf[montype] = gdf[montype].replace(dict(montype), regex=True)
When the term does not exist I get the error raise KeyError(f"None of [{key}] are in the [{axis_name}]")
Edit:
mtype = {
'HIS_COP_': '',
'_Ply': '',
'_Pt': '',
'BURIAL': 'burial',
'CUT': 'CUT',
'MODERN': 'MODERN',
'NATURAL': 'NATURAL',
'STRUCTURE': 'STRUCTURE',
'SURFACE': 'SURFACE',
'TREETHROW': 'natural feature',
'FURROW': 'FURROW',
'FIELD_DRAIN': 'FIELD_DRAIN',
'DEPOSIT_FILL': 'DEPOSIT_FILL',
'POSTHOLE': '',
'TIMBER': ''
} # dict(montype)
gdf['montype'] = gdf['montype'].map(mtype).fillna(gdf['montype'])
You can try this:
# Convert you list to dict
Montype={'His_cop':'','Modern':'Modern', etc...} # dict(montype)
gdf[montype]=gdf[montype].map(Montype).fillna('whatever value you want')
I already did it and in older odoo version this way it worked!
Cant see this 'kecske' signal in the log file. No error message. If I wrote some code before super, it hasn't any effect.
Any idea? Is it the right way?
class DemoWizard(models.TransientModel):
_name = 'demo.wizard'
name = fields.Char(string='Name')
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
log = logging.getLogger('demo.wizard.fields_view_get()')
log.debug('kecske')
return super(DemoWizard,self).fields_view_get(view_id, view_type, toolbar, submenu)
This is from Odoo10 source. The file is found in the anonymization addon. odoo/addons/anonymization/wizard/anonymize_wizard.py. Notice the call to super() and the use of keyword arguments as apposed to positional arguments.
Other than that your code looks correct.
In your example you initialised logging using a different technique. Try initialising your logger as follows.
log = logging.getLogger(__name__)
log.info("My Log Message")
or for debug.
log.debug("My debug message")
info,debug,warning,error can be used to log different degrees of severity of log messages.
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
state = self.env['ir.model.fields.anonymization']._get_global_state()
step = self.env.context.get('step', 'new_window')
res = super(IrModelFieldsAnonymizeWizard, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
eview = etree.fromstring(res['arch'])
placeholder = eview.xpath("group[#name='placeholder1']")
if len(placeholder):
placeholder = placeholder[0]
if step == 'new_window' and state == 'clear':
# clicked in the menu and the fields are not anonymized: warn the admin that backuping the db is very important
placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('label', {'string': 'Warning'}))
eview.remove(placeholder)
elif step == 'new_window' and state == 'anonymized':
# clicked in the menu and the fields are already anonymized
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('field', {'name': 'file_import', 'required': "1"}))
placeholder.addnext(etree.Element('label', {'string': 'Anonymization file'}))
eview.remove(placeholder)
elif step == 'just_anonymized':
# we just ran the anonymization process, we need the file export field
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('field', {'name': 'file_export'}))
# we need to remove the button:
buttons = eview.xpath("button")
for button in buttons:
eview.remove(button)
# and add a message:
placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('label', {'string': 'Result'}))
# remove the placeholer:
eview.remove(placeholder)
elif step == 'just_desanonymized':
# we just reversed the anonymization process, we don't need any field
# we need to remove the button
buttons = eview.xpath("button")
for button in buttons:
eview.remove(button)
# and add a message
placeholder.addnext(etree.Element('field', {'name': 'msg', 'colspan': '4', 'nolabel': '1'}))
placeholder.addnext(etree.Element('newline'))
placeholder.addnext(etree.Element('label', {'string': 'Result'}))
# remove the placeholer:
eview.remove(placeholder)
else:
raise UserError(_("The database anonymization is currently in an unstable state. Some fields are anonymized,"
" while some fields are not anonymized. You should try to solve this problem before trying to do anything else."))
res['arch'] = etree.tostring(eview)
return res
Python/Django newcomer here. Im getting a syntax error with the following code, can anyone help me out here? IDLE3 highlights Line 16 "Treasure" just before ("Fool's Gold").
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'index.html', {'treasures':treasures})
class Treasure:
def __init__(self, name, value, material, location):
self.name = name
self.value = value
self.material = material
self.location = location
treasures = [
Treasure('Gold Nugget', 500.00, 'gold', "Curley's Creek, NM")
Treasure("Fool's Gold", 0, 'pyrite', "Fool's Falls, CO")
Treasure('Coffee Can', 20.00, 'tin', 'Acme, CA')
]
You forgot to put commas after the elements of the array. Like this:
treasures = [
Treasure('Gold Nugget', 500.00, 'gold', "Curley's Creek, NM"),
Treasure("Fool's Gold", 0, 'pyrite', "Fool's Falls, CO"),
Treasure('Coffee Can', 20.00, 'tin', 'Acme, CA')
]