跳至內容
選單
此問題已被標幟
4 回覆
11104 瀏覽次數

Hi All,

class EquipmentCreation(models.Model):
    _name = "assets.creation"

     owner_user_id1 = fields.Many2one('res.users', string='Assignee',readonly=False)


class MaintenanceEquipment(models.Model):
    _inherit = "maintenance.equipment"

      owner_user_id = fields.Many2one('res.users', string='Assignee',readonly=False)


I need data of owner_user_id to owner_user_id1..the moment u save?

How to fetch the data by using create method..??

頭像
捨棄
最佳答案

Hi,

You can super the create method of the model maintenance.equipment and then search the record in the model  assets.creation (based on the relation) and write values into it.

@api.model
def create(self, vals):
res = super(Classname, self).create(vals)
#Here you can search the record in the another model
    #In the vals you will get the required values
#and write the values into it
return res

Also while posting the question use meaning full titles.
Thanks

頭像
捨棄
最佳答案

class MaintenanceEquipment(models.Model):
    _inherit = "maintenance.equipment"

      owner_user_id = fields.Many2one('res.users', string='Assignee',readonly=False)

      @api.model

      def create(self.vals)

          obj = super(MaintenanceEquipment, self).create(vals)

          print('XYZ', vals)

          if obj.owner_user_id:

              print('check in terminal for debugging', obj.owner_user_id)

              obj.owner_user_id.owner_user_id1 = obj.owner_user_id.id

          return obj

    

Go to front-end and do the following steps to see the result.

1. Go "assets.creation" object, and create one record. (here is your owner_user_id1 field in which you get the value by default.

2. Open link in new tab and go to "maintenance.equipment", create record and also fill owner_user_id as you want it to be print in "owner_user_id1".

3. Refresh the window of "assets.creation".

Thanks

Adesh Paul

頭像
捨棄
最佳答案

https://stackoverflow.com/questions/34171367/remove-create-and-edit-from-many2one-fieldlot-id-for-type-outgoing-using-f


I think this link will help you.

頭像
捨棄

The link is for removing the create and edit option from the Many2one field is right ?

相關帖文 回覆 瀏覽次數 活動
1
11月 24
20202
1
9月 23
3014
3
5月 23
5629
7
4月 23
48992
1
12月 22
7862