Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2031 Lượt xem

Hello, I have this code.


class HrExpenseExtended(models.Model):

    _inherit = 'hr.expense'


    def copy_expense(self,default=None):

        default = dict(default or {})

        default['name'] = self.name + ' (Copy)'

        new_log = super(HrExpenseExtended,self).copy(default)

        return {

            # 'name': self.order_id,

            'res_model': 'hr.expense',

            'type': 'ir.actions.act_window',

            'context': {},

            'view_mode': 'form',

            'view_type': 'form',

            'res_id': new_log.id,

            'view_id': self.env.ref("hr_expense.hr_expense_view_form").id,

            'target': 'current'

        }


There is a date field in the hr.expense model, what can I do so that when the user duplicates a record, that field can be automatically increased by 1 month?

Example: If you have a record created with a date of February 10, when I duplicate it, does the duplicate record appear with March 10?

Odoo 13 community, thanks and sorry for the inconvenience.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi 

You can import date_utlis in Python, and add one more month to the date. Here is an example 

from odoo.tools import date_utils
default['date'] = date_utils.add(self.date, months=1)

Regards




Ảnh đại diện
Huỷ bỏ
Tác giả

Greetings, and thanks for answering.
When I put that line of code I get this error:

psycopg2.errors.InvalidDatetimeFormat: invalid input syntax for type date: "31"
LINE 1: ... 30, (now() at time zone 'UTC'), 83, NULL, 2, 33, '31', 'Pag...

Tác giả

False alert, I already solved the problem, thank you very much!

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 6 25
1076
1
thg 1 25
17973
3
thg 8 24
15285
2
thg 7 24
2303
2
thg 5 24
2623