Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    Real Estate
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    Consulting
    • Accounting Firm
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • Solar Energy Systems
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    Others
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    รับการสาธิต
  • ราคา
  • ช่วยเหลือ

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

How to insert current date column in many2many relational table in odoo 8 ?

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
many2manydatetimeodoo8.0
3 ตอบกลับ
10751 มุมมอง
อวตาร
odooPrac

ok, so I've been stuck with this for a while now. I'm trying to create a current date field (date_added) in model stock.location.lock.code.rel (which is a relational model for stock.location.lock.code and stock.location models). My problem is that the table and field gets created in postgres db but its not getting populated and I'm getting error (mentioned below code). My code is below (I'm a beginner in odoo, so please do suggest correct way of doing)


in stock.location class :

class StockLocation(models.Model):

_name = 'stock.location'

_inherit = 'stock.location'


@api.multi

def write(self, vals): 

#I've overriden this method because I need to edit a form view and this method will be called when I press save button

now = datetime.now()

current_time = now.strftime('%m/%d/%Y %H:%M:%S')

vals = ({'date_added': current_time, 'active': True})

http.request.env['stock.location.lock.codes.rel'].create(vals)

return super(StockLocation, self).write(vals)


level = fields.Char('Level', size=1, default=None)

position = fields.Char('Position', size=1, default=None)

lock_code_ids = fields.Many2many('stock.location.lock.codes','stock_location_lock_code_rel','location_ids','lock_code_ids','Lock Code to apply', ondelete="cascade", default=None)

not_on_hand = fields.Boolean('not_on_hand', readonly=True, default=False)


class StockLocationLockCodeRel(models.Model):

_name = "stock.location.lock.code.rel"

location_ids = fields.Many2one('stock.location', 'Lock code location', required=True, ondelete="cascade")

lock_code_ids = fields.Many2one('stock.location.lock.codes', 'Lock code', required=True, ondelete="cascade")

active = fields.Boolean('Active', default=True)

date_added = fields.Datetime('Date Added')

id = fields.Char('id')


@api.multi

def create(self, vals):

return super(StockLocationLockCodeRel, self).create(vals)


Now my code for stock.location.lock.codes is :


from openerp import models, fields

class StockLocationLockCodes(models.Model):

_name = 'stock.location.lock.codes'

code = fields.Char('Code', size=2)

name = fields.Char('Name', size=100)

description = fields.Text('Description')

not_on_hand = fields.Boolean('On Hand', default=None)

unavailable = fields.Boolean('Available', default=None)

lock_in = fields.Boolean('Put', default=None)

lock_out = fields.Boolean('Pull', default=None)

active = fields.Boolean('Active', default=None)

show = fields.Boolean('Show in Location', default=None)

location_ids = fields.Many2many('stock.location','stock_location_lock_code_rel','lock_code_ids','location_ids','Lock code location', ondelete="cascade", default=None)


The error on logs is :


Traceback (most recent call last):

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 551, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 588, in dispatch

result = self._call_function(**self.params)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 324, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/service/model.py", line 118, in wrapper

return f(dbname, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 321, in checked_call

return self.endpoint(*a, **kw)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 817, in __call__

return self.method(*args, **kw)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 417, in response_wrap

response = f(*args, **kw)

File "/home/rohitupadhyay/git/odoo-IC-32/addons/web/controllers/main.py", line 944, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/addons/web/controllers/main.py", line 936, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 268, in wrapper

return old_api(self, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 399, in old_api

result = method(recs, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/staples-addons/wms_stock/models/stock_location.py", line 167, in write

http.request.env['stock.location.lock.code.rel'].create(vals)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 266, in wrapper

return new_api(self, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/staples-addons/wms_stock/models/stock_location.py", line 275, in create

return super(StockLocationLockCodeRel, self).create(vals)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 266, in wrapper

return new_api(self, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/models.py", line 4094, in create

record = self.browse(self._create(old_vals))

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 266, in wrapper

return new_api(self, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 508, in new_api

result = method(self._model, cr, uid, *args, **old_kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/models.py", line 4232, in _create

tuple([u[2] for u in updates if len(u) > 2])

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/sql_db.py", line 158, in wrapper

return f(self, *args, **kwargs)

File "/home/rohitupadhyay/git/odoo-IC-32/openerp/sql_db.py", line 234, in execute

res = self._obj.execute(query, params)

ProgrammingError: column "id" of relation "stock_location_lock_code_rel" does not exist

LINE 1: INSERT INTO "stock_location_lock_code_rel" ("id", "active", ...

0
อวตาร
ละทิ้ง
อวตาร
Deepa Venkatesh
คำตอบที่ดีที่สุด

First you need the understand of concept of Many2Many relation & its table

A relation table created between 2 objects is just used to store the link of those, ideally it will have 2 fields, i.e ID of respective tables, hence you can not create any column in it. 

2
อวตาร
ละทิ้ง
อวตาร
odooPrac
ผู้เขียน คำตอบที่ดีที่สุด

thank you deep for your reply, but it is possible to add an extra field in Many2Many relational table. Please see this link :

https://www.odoo.com/forum/help-1/question/can-i-add-a-field-to-many2many-relation-table-30118

Also, there is a many2many relational table in odoo by name "im_chat_session_res_users_rel" which has more than 2 columns. I also looked into its source code before posting this question, but unable to figure out how this has been done. Thanks

0
อวตาร
ละทิ้ง
อวตาร
John Doe
คำตอบที่ดีที่สุด

I used the following in OERP 7, which I believe it very similar to OERP 8 (aka ODOO)

class left_model(osv.osv):
_name = 'left.model'


_columns = {
'rigths': fields.many2many(obj='right.model.id', rel='left_model_right_model_rel', id1='left_model_id', id2='right_model_id', string='Rigths'),
}

left_model()


class right_model(osv.osv):
_name = 'right.model'


_columns = {
'lefts': fields.many2many(obj='left.model.id', rel='left_model_right_model_rel', id1='right_model_id', id2='left_model_id', string='Lefts'),
}

right_model()


class center_model(osv.osv):
_name = 'center.model'
_table = 'left_model_right_model_rel' # this should match the rel argument in the other two models OR what ever OERP auto created.


_columns = {
'left_model_id': fields.many2one(obj='left.model.id', string='Left Model ID'),
'right_model_id': fields.many2one(obj='right.model.id', string='Right Model ID'),
'new_field': fields.char(string='New Field'), # this is your new field, customize it to your needs
}

center_model()

In this example the new field is a char which the original question would have customized to his required type.




0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
Datetime in Odoo แก้ไขแล้ว
datetime odoo8.0
อวตาร
อวตาร
อวตาร
2
ก.ค. 18
7649
From Datetime to Date แก้ไขแล้ว
datetime odoo8.0
อวตาร
อวตาร
1
ส.ค. 15
5047
Add a constraint to a many2many field แก้ไขแล้ว
constraint many2many odoo8.0
อวตาร
อวตาร
1
มิ.ย. 17
8157
Cannot execute name_create, no _rec_name defined แก้ไขแล้ว
many2many name_search many2many_tags odoo8.0
อวตาร
1
ม.ค. 22
11375
How to filter for any day of the week in odoo
filter date datetime odoo8.0
อวตาร
0
เม.ย. 18
6506
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ Odoo คือการใช้งานที่ง่ายดายและผสานการทำงานอย่างสมบูรณ์แบบในเวลาเดียวกัน

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now