I have this method:
@api.multi
def create_print(self):
rec_production_order = self.env['bsi.production.order'].browse(1)
self.env['bsi.print.order'].create({
'origin': rec_production_order.id,
'state': 'draft',
})
Which should create another model, from bsi.production.order
, these are the two complete models:
class bsi_production_order(models.Model):
_name = 'bsi.production.order'
_inherit = ['product.product']
@api.model
def create(self, vals):
if vals.get('name', 'New') == 'New':
if vals.get('production_type') == 'budgeted':
vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.budgeted') or '/'
elif vals.get('production_type') == 'nonbudgeted':
vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.non_budgeted') or '/'
elif vals.get('production_type') == 'direct':
vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.direct') or '/'
return super(bsi_production_order, self).create(vals)
name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
date = fields.Date(string="Production Date")
notes = fields.Text(string="Notes")
order_lines = fields.One2many('bsi.production.order.lines', 'production_order', states={'finished': [('readonly', True)], 'cancel': [('readonly', True)]}, string="Order lines", copy=True)
print_orders = fields.One2many('bsi.print.order', 'production_orders', string="Print Orders")
class bsi_print_order(models.Model):
_name = 'bsi.print.order'
_inherit = ['mail.thread','mrp.worksheet.contract']
name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
date = fields.Date(string="Print Date")
production_orders = fields.Many2one('bsi.production.order', ondelete='cascade', string="Production Order")
origin = fields.Char(string="Origin")
due_date = fields.Date(string="Due Date")
state = fields.Selection([
('draft','Draft'),
('awaitingraw','Awaiting raw materials'),
('wip','Work in Progress'),
('delivered','Delivered'),
('cancel','Cancel'),
], string="State")
notes = fields.Text(string="Notes")
The method works, but on origin
field from bsi.print.order
it just creates a 1, it is supposed to be the name
from bsi.production.order
, not a number, also, what is weird about this, is the fact that, no matter how many print orders I create, it always puts a number 1 in there.
Any ideas?