Python 自动创建任意字段
我希望我能清楚地解释我的问题。在账户模块中,我们有与One2任意关系相关的Python 自动创建任意字段,python,odoo-10,Python,Odoo 10,我希望我能清楚地解释我的问题。在账户模块中,我们有与One2任意关系相关的account.payment.term和account.payment.term.line模型: class AccountPaymentTerm(models.Model): _name = "account.payment.term" _description = "Payment Term" line_ids = fields.One2many('account.payment.term.
account.payment.term
和account.payment.term.line
模型:
class AccountPaymentTerm(models.Model):
_name = "account.payment.term"
_description = "Payment Term"
line_ids = fields.One2many('account.payment.term.line', 'payment_id', string='Terms', copy=True, default=_default_line_ids)
period = fields.Selection([('month', '1 Month'),], string='Period', required=True, default='month', help="Select here the period between payments")
how_much = fields.Float()
fixed_amount = fields.Float()
class AccountPaymentTermLine(models.Model):
_name = "account.payment.term.line"
_description = "Payment Term Line"
payment_id = fields.Many2one('account.payment.term', string='Payment Terms', required=True, index=True, ondelete='cascade')
我想在account.payment.term
中创建一个方法,自动创建付款条件行。此方法应确定切片数<代码>切片数=(self.多少/self.固定金额)这将是付款条件行数。我现在尝试了以下代码:
@api.onchange('fixed_amount')
def automate_creation(self):
terms = self.line_ids.browse([])
self.number_of_slices = (self.how_much/self.fixed_amount)
i = 0
while i<10:
terms+=terms.new({'value': 'fixed',
'value_amount':100,
'days':30,
'option':'day_after_invoice_date',
'payment_id':self._origin.id})
i=i+1
@api.onchange(“固定金额”)
def自动创建(自):
terms=self.line\u id.browse([])
self.number\u of\u切片=(self.how\u mound/self.fixed\u amount)
i=0
而我试试这个
@api.onchange('fixed_amount')
def automate_creation(self):
self.number_of_slices = (self.how_much/self.fixed_amount)
i = 0
while i<10:
term = self.line_ids.create({'value': 'fixed',
'value_amount':100,
'days':30,
'option':'day_after_invoice_date',
'payment_id':self._origin.id})
self.line_ids |= term
i=i+1
@api.onchange(“固定金额”)
def自动创建(自):
self.number\u of\u切片=(self.how\u mound/self.fixed\u amount)
i=0
当我这段代码解决了我的问题时,我使用了new
而不是create
@api.onchange('fixed_amount')
def automate_creation(self):
terms = self.line_ids.browse([])
self.number_of_slices = (self.how_much/self.fixed_amount)
days = 30
i = 0
while i<self.number_of_slices:
terms+=terms.new({'value': 'fixed',
'value_amount':self.fixed_amount,
'days':days,
'option':'day_after_invoice_date',
'payment_id':self._origin.id})
self.line_ids = terms
@api.onchange(“固定金额”)
def自动创建(自):
terms=self.line\u id.browse([])
self.number\u of\u切片=(self.how\u mound/self.fixed\u amount)
天数=30天
i=0
你能给我解释一下create
和new
之间的区别吗?