I'm new to odoo and trying to add a new module to sales.
I have added a module and a field called job_no, it is placed in the sales order tree view.
my goal is to automatically generate sequential values in the job_no field when the confirm button is pressed.
but I'm having trouble connecting the confirmation button that is already in odoo.
here is the code i have made:
this is a .py file
from odoo import api, fields, models, _
class sale_warisan(models.Model):
_inherit = 'sale.order'
jenis_pekerjaan = fields.Selection([
('jasa', 'Jasa'),
('proyek', 'Proyek'),
('belt', 'Belt'),
('aksesoris', 'Aksesoris'),
], required=True, default='aksesoris', tracking=True)
job_no = fields.Char(string='Job Number', tracking=True, copy=False, readonly=True,
default=lambda self: _('New'))
# ignore this one, because I'm still looking for tutorials on the web and youtube, but I haven't been able to get it working
# def create(self, vals):
# if vals.get('job_no', _('New')) == _('New'):
# vals['job_no'] = self.env['ir.sequence'].next_by_code('sales.order') or _('New')
# res = super(sale_warisan, self).create(vals)
# return res
and this .xml
xml version="1.0" encoding="UTF-8" ?>
id="tampilan_quotation_form_warisan" model="ir.ui.view">
name="name">tampilan.quotation.warisan
name="model">sale.order
name="inherit_id" ref="sale.view_order_form"/>
name="arch" type="xml">
expr="//field[@name='partner_id']" position="after">
name="jenis_pekerjaan"/>
id="tampilan_quotation_tree_warisan" model="ir.ui.view">
name="name">tampilan.quotation.warisan
name="model">sale.order
name="inherit_id" ref="sale.view_quotation_tree"/>
name="arch" type="xml">
expr="//field[@name='partner_id']" position="after">
name="jenis_pekerjaan"/>
id="urutan_job_no" model="ir.sequence">
name="name">Job Number
name="code">sale.order
name="padding">4
id="tampilan_order_tree_warisan" model="ir.ui.view">
name="name">tampilan.order.warisan
name="model">sale.order
name="inherit_id" ref="sale.view_order_tree"/>
name="arch" type="xml">
expr="//field[@name='name']" position="before">
name="job_no"/>