Fill the date field (today date) automatically o when you access to a view - view

I want to change the value of field ( that changes to the date of the day for example)
automatically or when you access an already created view the action is generate in odoo13.
Thaks

You should use fields_view_get method, it will fired with every type of view, if you need it when a form is open you can do something like this:
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(Movimiento, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
)
if view_type == 'form':
# Get today date
today = fields.Date.context_today(self)
# update your field here.
return res
I hope this answer can be helpful for you.

Related

Vuetify v-calendar #change start end and days not includes past or next month days

I am trying to create v-calendar with vuetify.
The problem is when i use #change event it does not includes date range viewed on crud like fullcalendar. How can i get those days?
<v-calendar
ref="calendar"
v-model="focus"
:events="events"
#change="updateRange"
></v-calendar>
methot
updateRange ({ start, end }) {
// start.date and end.date gives first/end day of the month instate of range of crud
this.events = this.getEvents(start.date, end.date)
)}
I also answered this on another question, but I'll answer here too.
If you're in the monthly view, there is a 'days' computed property on the VCalendarMonthly/Weekly component that uses some methods to calculate the start and end dates.
You can access those base methods via the calendar ref to get the start/end dates in view.
Your method would then look something like this:
updateRange ({ start, end }) {
viewStart = this.$refs.calendar.getStartOfWeek(start);
viewEnd = this.$refs.calendar.getEndOfWeek(end);
this.events = this.getEvents(viewStart.date, viewEnd.date);
)}

How to update attributes while doing a duplicate Rails

We are creating a scheduling app and attempting to create a copy/paste function for schedules from week to week. I am trying to figure out how to duplicate a schedule for certain period of time, while updating the attributes upon paste. Right now I can copy the schedule, but when running it on postman, the dates and times stay the exact same (as we would expect with a .dup.) I believe it would be best to set the start/end times to nil and then upon paste maybe the attributes get updated at that time?
Here is the function I have so far:
def copy
set_calendar
if params["start_date"] && params["end_date"]
start_date = params["start_date"].to_date
end_date = params["end_date"].to_date
if #calendar.users.owners.include?(current_user) || #calendar.users.managers.include?(current_user)
#past_shifts = Shift.where(calendar_id: #calendar.id, start_time: start_date.beginning_of_day .. end_date.end_of_day).to_a
if
#past_shifts.each do |past_shift|
shift = past_shift.dup
shift.users = past_shift.users
shift.update(shift_params)
shift.save
end
render json: "copied", status: :ok
else
render json: #usershift.errors, status: :uprocessable_entity
end
else
render json: ("You do not have access to copy shifts"), status: :unauthorized
end
end
end
The shift.update(shift_params) is the part that needs to update the start and end times. Here are the shift params:
def shift_params
params.permit(:start_time, :end_time, :calendar_id, :capacity, :published)
end
As far as relationship set ups, this current method is being created in the shifts controller. Shift has many users through usershifts, user has many shifts through usershifts, and usershift model belongs to both.
Just curious - are you sure params for your copy method contains values for start_time and end_time? If so, why not to use them directly:
shift.start_time = params['start_time']
shift.end_time = params['end_time']
With use shift_params you will also update other 3 attributes: :calendar_id, :capacity, :published. Not sure if this is necessary in this case.
Using shift.update method, in this case, is not reasonable. It works with existing record and saves updated attributes to the database. In your case the record is new, and you save all the changes with calling shift.save later.

How to update invoice.line quantity ?

I am trying to create button in Invoice that will update certain field in inovoice lines. I've found how to update field in account.invoice but I am strugling to find right way how to update it in account.invoice.line.
class accountinvoiceext(models.Model):
_inherit = ['account.invoice']
#api.one
def my_button(self,uid):
invoice_id = self.id
#lines = getinvoicelinesbyid(invoice_id)
I am sure there is some proper way how to get invoice.lines related to this invoice, or not ?
I've tried _inherit account.invoice.line but then I cannot define button there.
Second question - what is best way to call some function every time invoice is created ?
if you want to add button to change the line. you need to loops the one2many fields in the invoice, and change #api.one to #api.multi, example:
#api.multi
def my_button(self):
for line in self.invoice_line:
line.write({'your_field': 'your_values'})
and if you want to call this function every invoice is create, you need to modified the create function:
#api.multi
def create_project(self,values):
res = super(SaleOrder, self).create(values)
res.my_button()
return res

inherit product_id_change and add new argument odoo 8

i'm working on sale.order.line ,adding new field lot
lot = fields.Many2one('stock.production.lot','lot')
and i want pass this field as argument into an inherited method (onchange on quantity )
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, lot=False,context=None):
res = super(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=context)
if product:
print "----------------------------------------------"
print lot
print "----------------------------------------------"
# res['value']['changement_prix'] = lot.change_prix
# res['value']['old_price'] = res['value']['price_unit']
# res['value']['price_unit'] = res['value']['old_price'] + lot.change_prix
return res
but all i got in my print is False for lot
so im wondering how to pass lot as argument on this function
thnx
You can not pass new argument this way in function.
Its call super method of object, it will create problem in the super method also. So either you can pass lot in context for xml side,
like
<field name="product_id"
context="{'partner_id':parent.partner_id,
'quantity':product_uom_qty,
'pricelist':parent.pricelist_id,
'uom':product_uom, 'company_id': parent.company_id,
'lot': lot}" <======
groups="base.group_user"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, False, product_uos_qty, False, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)"/>
So in context you get you passed the lot.
lot = context.get('lot')
in python side you get from context and done your code.
Otherwise you have to overwrite whole function of onchange in your new modules
change in xml side for arguements of onchange
Hope this will help you.
well i couldnt get lot by context
so i made an invisible field many2one in product.product
and save it there .
than get it back later by browsing my product
thnx

date function error in rails 3

I am trying to add a date conditional to my controller index action:
#events = Event.where("date" => Date.today.to_s).order("date").page(params[:page]).per_page(5)
I am trying to make my view only show events that have a date value greater than or equal to today's date. For example if an event has a date value of 2013-05-13 it should not be shown because that event has already happened and only events with a date value of today's date or later should be shown.
The problem is, the index view isn't returning any events and I have created an with a date value of 2013-05-30 which means it should work. Any ideas?
Thanks in advance
This is actually going to return everything where the date equals today:
Event.where("date" => Date.today.to_s)
What you probably want instead is:
Event.where("date >= ?", Date.today)
ActiveRecord will interpolate the date into the ?. Also, you don't need to call to_s on it, ActiveRecord will the date for you.
Try this:
In your model use a scope like so:
scope :recent_event, lambda { where('date >= ?', Date.today ) }
Then in your controller write
#events = Event.recent_event.order("date").page(params[:page]).per_page(5)

Resources