0

I want to achieve a similar function in our own modules: when I create a record, dynamically generated in the message module, and not just in the bottom of the page.

I found the sales module have similar functions, and the purchase module not, study also found no principle, inherited the mail.thread doesn't work, I was very depressed.

the relevant *.py code:

class jp_stock_picking(osv.osv):
   _name = "jp.stock.picking"
   _inherit = ['mail.thread', 'ir.needaction_mixin']
   _description = "Picking List"

   _track = {
    'state': {
        'stock_jiup.mt_wait_prove': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['wait_prove','overrule','wait_check','checked','cancel']
    },
}
def get_employee(self, cr, uid, context={}):
    obj = self.pool.get('hr.employee')
    ids = obj.search(cr, uid, [('user_id','=',uid)])
    res = obj.read(cr, uid, ids, ['id','name'], context)
    return res and res[0]['id'] or 0

_columns = {
    'name': fields.char('Reference',size=20),
    'document_id': fields.char('Document Number',size=16, required=True),
    'supplier_id': fields.many2one('res.partner', 'Supplier', required=True),
    'create_time': fields.datetime('Create Time', required=True),
    'operator': fields.many2one('hr.employee', 'Operator Perosn', required=True),
    'origin': fields.char('Come From',size=50, required=True),
    'state': fields.selection([('draft', 'New'),
       ('wait_handle','Wait Handle'),
       ('wait_prove', 'Wait Prove'),
       ('overrule', 'Overrule'),
       ('wait_check', 'Wait Quality Checking'),
       ('checked', 'Quality Checked'),
       ('cancel', 'Cancel'),
        ], 'Status', readonly=True, select=True, track_visibility='always'
    ),
    'move_lines': fields.one2many('jp.stock.move', 'jp_picking_id', 'Internal Moves', readonly=True, states={'draft': [('readonly', False)],'wait_handle':[('readonly', False)],'overrule':[('readonly', False)]}),
    'remark': fields.text('Remark')
}

this is relevant *_data.xml code :

<record id="mt_wait_prove" model="mail.message.subtype">
        <field name="name">Picking Prove</field>
        <field name="res_model">jp.stock.picking</field>
        <field name="default" eval="False"/>
        <field name="description">Picking Prove</field>
</record>
luckbo
  • 11
  • 3

1 Answers1

0

inherit

_inherit = ['mail.thread', 'ir.needaction_mixin']

for field you want to generate message add track_visibility='always'

_columns = {
    'tot_usr_fee': fields.float('Total User Fees', track_visibility='always'),
}

Then in view file add

    <record id="mt_shipment_statement_invoice" model="mail.message.subtype">
        <field name="name">Custom Statement Invoice Generated</field>
        <field name="res_model">shipment.statements</field>
        <field name="default" eval="False"/>
        <field name="description">Invoice Generated</field>
    </record>
    <record id="mt_shipment_statement_confirmed" model="mail.message.subtype">
        <field name="name">Custom Statement Confirmed</field>
        <field name="res_model">shipment.statements</field>
        <field name="default" eval="False"/>
        <field name="description">Invoice confirmed</field>
    </record>
Abhishek Jaiswal
  • 2,524
  • 1
  • 21
  • 24