Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
26322 Lượt xem

I am using odoo 9, and I have inherited the invoicing module. In the python code I tried to change the name of one of the invoice.lines fields, basically the quantity. The change is reflected in the model when I go and check the DB structure. However, the form is viewed with the base model field string which is "Quantity"! The xml file does not give any string name to the field, so it does not override. I don't know what is wrong there!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I also wanted to change the string of an inherited field.

To do so, you can just re-declare the field with the attributes you want to override. The rest is taken from the base class:

class ModelA(models.Model):
_name='module.model_a'
my_field = fields.Many2one('product.product', string='MyField')

class ModelB(models.Model):
_name='module.model_b'
_inherit = 'module.model_a'
my_field = fields.Many2one(string='NewNameDisplayName') # The rest is taken from ModelA

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Do not forget to add in your module, in file __openerp__.py:

'depends': [ 'account', ]

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Mounir zitouni, 

your suggestion is so helpfull for me :)

thnx

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you Mounir and zbik,
I have already added account as a module on which the one I am implementing depends:
'depends':['account']
has already been done.
As for the attributes I am just wondering why it couldn't be done from the python code?
The thing that is surprising me is that in the settings, under the database structure, the field string in the model is correctly showing the string I have given it in the python code. However, in the form it just views it with the string in the base model!

Ảnh đại diện
Huỷ bỏ

Probably something wrong you have done, show your code.

Tác giả

Hi zblik,

Sorry for my late response. Here is the line of code where I changed the string:

# quantity = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'),

quantity = fields.Float(string='Time', digits=dp.get_precision('Service Unit of Measure'),

-------

This is line number (approximately) 1132 in the account_invoice.py.

Câu trả lời hay nhất

You can use "attributes"  .For Example:

<xpath expr="//field[@name='number']" position="attributes">

<attribute name="string" >Reference</attribute>

</xpath>

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 24
1832
2
thg 8 23
3245
2
thg 8 23
43226
3
thg 4 23
2355
3
thg 12 22
33938