Skip to Content
Menu
This question has been flagged

Hello every one!

Did any one know how to putting a field like 'number' or 'date' inside not in form view like the photo below?

actually i want it to store that field inside note before starting to write any other thing like it work in mail or to be able making a template and choosing that to get the whole format included that extra fields


Avatar
Discard
Best Answer

Hello, the below will works during create 

class SaleOrder(models.Model):


    _inherit = 'sale.order'

    

    def _compute_note_date(self):

        return self._context.get('uid')

        

    note = fields.Text(default=_compute_note_date)

Or if you want it on onchange then, follow the below code


class SaleOrder(models.Model):


    _inherit = 'sale.order'

    

    @api.onchange('amount_total')

    def _compute_note_date(self):

        self.note =  self.amount_total

        

    note = fields.Text(digits=(16,4))

Avatar
Discard
Author

Hi

It seems i didn't understand how you said, so what changes i need to do in xml files?

i meant form view

this is the code that i want to do that

from openerp import models, fields, api, tools

from openerp.tools import html2plaintext

from lxml import etree

from openerp.tools.safe_eval import safe_eval as eval

from openerp.tools.translate import _

class ResLetter(models.Model):

"""A register class to log all movements regarding letters"""

_name = 'res.letter'

_description = "Log of Letter Movements"

_inherit = 'mail.thread'

number = fields.Char(

help="Auto Generated Number of letter.",

default="/")

name = fields.Text(

string='Subject',

help="Subject of letter.")

move = fields.Selection(

[('in', 'و'), ('out', 'OUT')],

help="Incoming or Outgoing Letter.",

readonly=True,

default=lambda self: self.env.context.get('move', 'in'))

state = fields.Selection(

[

('draft', 'Draft'),

('sent', 'Sent'),

('rec', 'Received'),

('rec_bad', 'Received Damage'),

('rec_ret', 'Received But Returned'),

('cancel', 'Cancelled'),

],

default='draft',

readonly=True,

copy=False,

track_visibility='onchange',

help="""

* Draft: not confirmed yet.\n

* Sent: has been sent, can't be modified anymore.\n

* Received: has arrived.\n

* Received Damage: has been received with damages.\n

* Received But Returned: has been received but returned.\n

* Cancel: has been cancelled, can't be sent anymore."""

)

date = fields.Date(

string='Letter Date',

help='The letter\'s date.',

default=fields.Date.today)

snd_date = fields.Date(

string='Sent Date',

help='The date the letter was sent.')

rec_date = fields.Date(

string='Received Date',

help='The date the letter was received.')

def default_recipient(self):

move_type = self.env.context.get('move', False)

if move_type == 'in':

return self.env.user.company_id.partner_id

def default_sender(self):

move_type = self.env.context.get('move', False)

if move_type == 'out':

return self.env.user.company_id.partner_id

recipient_partner_id = fields.Many2one(

'res.partner',

string='Recipient',

track_visibility='onchange',

# required=True, TODO: make it required in 9.0

default=default_recipient)

sender_partner_id = fields.Many2one(

'res.partner',

string='Sender',

track_visibility='onchange',

# required=True, TODO: make it required in 9.0

default=default_sender)

note = fields.Text(

string='Delivery Notes',

help='Indications for the delivery officer.')

channel_id = fields.Many2one(

'letter.channel',

string="Channel",

help='Sent / Receive Source')

category_ids = fields.Many2many(

'letter.category',

string="Tags",

help="Classification of Document.")

folder_id = fields.Many2one(

'letter.folder',

string='Folder',

help='Folder which contains letter.')

type_id = fields.Many2one(

'letter.type',

string="Type",

help="Type of Letter, Depending upon size.")

weight = fields.Float(help='Weight (in KG)')

size = fields.Char(help='Size of the package.')

track_ref = fields.Char(

string='Tracking Reference',

help="Reference Number used for Tracking.")

orig_ref = fields.Char(

string='Original Reference',

help="Reference Number at Origin.")

expeditor_ref = fields.Char(

string='Expeditor Reference',

help="Reference Number used by Expeditor.")

parent_id = fields.Many2one(

'res.letter',

string='Parent',

groups='lettermgmt.group_letter_thread')

child_line = fields.One2many(

'res.letter',

'parent_id',

string='Letter Lines',

groups='lettermgmt.group_letter_thread')

reassignment_ids = fields.One2many(

'letter.reassignment',

'letter_id',

string='Reassignment lines',

help='Reassignment users and comments',

groups='lettermgmt.group_letter_reasignment')

# This field seems to be unused. TODO: Remove it?

extern_partner_ids = fields.Many2many(

'res.partner',

string='Recipients')

@api.model

def create(self, vals):

if ('number' not in vals) or (vals.get('number') in ('/', False)):

sequence = self.env['ir.sequence']

move_type = vals.get('move', self.env.context.get(

'default_move', self.env.context.get('move', 'in')))

vals['number'] = sequence.get('%s.letter' % move_type)

return super(ResLetter, self).create(vals)

@api.one

def action_cancel(self):

""" Put the state of the letter into Cancelled """

self.write({'state': 'cancel'})

return True

@api.one

def action_cancel_draft(self):

""" Go from cancelled state to draf state """

self.write({'state': 'draft'})

return True

@api.one

def action_send(self):

""" Put the state of the letter into sent """

self.write({

'state': 'sent',

'snd_date': self.snd_date or fields.Date.today()

})

return True

@api.one

def action_received(self):

""" Put the state of the letter into Received """

self.write({

'state': 'rec',

'rec_date': self.rec_date or fields.Date.today()

})

return True

@api.one

def action_rec_ret(self):

""" Put the state of the letter into Received but Returned """

self.write({

'state': 'rec_ret',

'rec_date': self.rec_date or fields.Date.today()

})

return True

@api.one

def action_rec_bad(self):

""" Put the state of the letter into Received but Damaged """

self.write({

'state': 'rec_bad',

'rec_date': self.rec_date or fields.Date.today()

})

return True

Hello Berctain, just define it only in python itself. that's enough to set whatever field u want. No changes in xml view.

eg:

class ResLetter(models.Model):

_name = 'res.letter'

@api.onchange('amount_total')

def _compute_note_date(self):

self.name = self.expeditor_ref

note = fields.Text(digits=(16,4))

its name = fields.Text() not note

Author

Thanks Annadurai,

it worked for date field but in number field since that field create automatically with system on create then this code just put one slash inside note, need to change it to create, and another thing is i would have this data inside a special tables and read only .. so how can i make a template for this note field.. like a selectable template?!

Related Posts Replies Views Activity
0
Jul 24
225
1
Sep 23
708
1
Jun 23
1872
1
Mar 24
2521
0
Nov 22
1339