39 lines
1.7 KiB
Python
39 lines
1.7 KiB
Python
from odoo import models, fields, api
|
|
|
|
class GaAssetTransferWizard(models.TransientModel):
|
|
_name = 'ga.asset.transfer.wizard'
|
|
_description = 'Asset Transfer Wizard'
|
|
|
|
asset_id = fields.Many2one('account.asset', string='Asset', required=True, readonly=True)
|
|
current_company_id = fields.Many2one('res.company', string='Current Company', required=True, readonly=True)
|
|
target_company_id = fields.Many2one('res.company', string='Target Company', required=True)
|
|
note = fields.Text(string='Transfer Note')
|
|
|
|
def action_transfer(self):
|
|
self.ensure_one()
|
|
if self.target_company_id and self.target_company_id != self.current_company_id:
|
|
# Create Transfer Log
|
|
transfer_log = self.env['ga.asset.transfer.log'].create({
|
|
'asset_id': self.asset_id.id,
|
|
'source_company_id': self.current_company_id.id,
|
|
'target_company_id': self.target_company_id.id,
|
|
'note': self.note,
|
|
'state': 'transit',
|
|
})
|
|
|
|
# Lock Asset
|
|
self.asset_id.sudo().write({'in_transit': True})
|
|
self.asset_id.message_post(body=f"Asset transfer initiated to {self.target_company_id.name}. Waiting for validation. Ref: {transfer_log.name}")
|
|
|
|
return {
|
|
'type': 'ir.actions.client',
|
|
'tag': 'display_notification',
|
|
'params': {
|
|
'title': 'Transfer Initiated',
|
|
'message': f"Asset transfer to {self.target_company_id.name} is now pending validation.",
|
|
'sticky': False,
|
|
}
|
|
}
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|