콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
2432 화면

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
2726
1
12월 24
2490
2
3월 24
2839
2
3월 24
3359
0
9월 23
1836