Hilfe

0

Retreive Value from Custom Field to another Custom Field

Avatar
YME

Hello,


I've created a Custom Field (size_of_pieces) in the Manufacturing Order screen and another Customer field (size_of_pieces_inv) in the Inventory Transfers screen.

When the user enters a value for: size_of_pieces I want size_of_pieces_inv to automatically take that value. How would I go about doing that?


My Code:

models.py :
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class mo_screen(models.Model):
    _inherit = 'mrp.production'
   
    size_of_pieces = fields.Char(string='Size of Pieces', store=True, readonly=False)
   

   
class inv_screen(models.Model):
    _inherit = 'stock.picking'
   
    size_of_pieces_inv = fields.Many2one('mo.screen', string='Size of Pieces', store=True, readonly=False)


views.xml :
<odoo>
  <data>
      <record id="mrp_production_form_view_inherits" model="ir.ui.view">
            <field name="name">mrp.production.form</field>
            <field name="model">mrp.production</field>
            <field name="priority" eval="40"/>
            <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//form/sheet/group/group/field[@name='bom_id']" position="after"> 
                    <field name="size_of_pieces"/>
                </xpath>
            </field>
      </record>
  </data>
</odoo>



inv_views.xml :
<odoo>
  <data>
      <record id="view_picking_form_inherit" model="ir.ui.view">
            <field name="name">stock.picking.form.inherit</field>
            <field name="model">stock.picking</field>
            <field name="priority" eval="40"/>
            <field name="inherit_id" ref="stock.view_picking_form"/>
            <field name="arch" type="xml">
                <xpath expr="//group/group/field[@name='picking_type_id']" position="after"> 
                    <field name="size_of_pieces_inv"/>
                </xpath>
            </field>
      </record>
  </data>
</odoo>



Any help is appreciated, thanks in advance!

Avatar
Verwerfen
1 Antwort
0
Avatar
Nuraddin
Best Answer

Hi. 

You may try onchange method on your  mo_screen model, this example from documentation

@api.onchange('amount', 'unit_price')
def _onchange_price(self):
    # set auto-changing field
    self.price = self.amount * self.unit_price
    # Can optionally return a warning and domains
    return {
        'warning': {
            'title': "Something bad happened",
            'message': "It was very bad indeed",
        }
    }
1 Kommentar
Avatar
Verwerfen
Avatar
YME
-

Hey, thanks for replying. I changed my code to this, but it didn't work unfortunately:

# -*- coding: utf-8 -*-

from odoo import models, fields, api

class mo_screen(models.Model):

_inherit = 'mrp.production'

size_of_pieces = fields.Char(string='Size of Pieces', store=True, readonly=False)

api.onchange('size_of_pieces')

def _onchange_size(self):

# set auto-changing field

self.size_of_pieces_inv = self.size_of_pieces

class inv_screen(models.Model):

_inherit = 'stock.picking'

size_of_pieces_inv = fields.Char(string='Size of Pieces', readonly=False)

# size_of_pieces_inv = fields.Many2one('mrp.production', string='Size of Pieces', store=True, readonly=False)