跳至內容
選單
此問題已被標幟
2 回覆
1966 瀏覽次數

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"/>





頭像
捨棄
作者 最佳答案

Hi,

thanks for the answer, I've tried it but the message appears: TypeError: object 'bool' does not support item assignment.

頭像
捨棄
作者

after i tried again it worked.

with the following code:
def action_confirm(self):
res = super(SaleOrder, self).action_confirm()
if self.env.su:
self = self.with_user(SUPERUSER_ID)

for jb in self:
if jb.job_no == _('Offer'):
jb.job_no = self.env['ir.sequence'].next_by_code('job.order') or _('Offer')
return res

最佳答案

Hi,

If you are looking to generate the sequence number in the newly added field on confirming the sales order, instead of inheriting the create method, you have to inherit the function that get executed on clicking the confirm button.


In sale.order model on clicking the confirm button action_confirm method is getting executed, thus super this method in your module and add the logic to generate the sequence.


def action_confirm(self):
res = super(SaleOrder, self).action_confirm()
res.job_no = self.env['ir.sequence'].next_by_code('sales.order') or _('New')
return res



Thanks

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
2月 25
1622
1
12月 24
1825
2
3月 24
2172
2
3月 24
2698
0
9月 23
1326