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

I have two model, purchase.pi and purchase.order

I have order lines in purchase.pi

Now, I'm trying to get the order lines from purchase.pi and populate the order lines of purchase.order model, based on the selection of order_id. The order_id can be one or more, and order lines will be added one after another.

But, the problem is after selecting the second order_id I get its own order lines and the previously selected order line again.
Below is my code:

		​
class PurhcasePi(models.Model):
​_name="purchase.order.pi.copy"
​_inherit= ['purchase.order','mail.thread', 'mail.activity.mixin']
​_description="Purchase order copy"
​order_line= fields.One2many('purchase.order.pi.line.copy', 'order_id', string='Order Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True) ​lc_id= fields.Many2one('purchase.order', string='LC')
​def_create_lc_lines_context(self, lc_id):
​​lines= []
​for line in self.order_line:
​​if line.product_qty >0:
​​lines.append(
​​(0, 0, {
​​​'product_id': line.product_id.id,
​'name': line.name,
​'product_uom':line.product_uom,
​'price_unit':line.price_unit,
​'price_subtotal':line.price_subtotal,
​'product_qty': line.product_qty,
​                    ​​}
​                ​))
​else:
​continue
​return lines
class lc(models.Model):
​_inherit='purchase.order'

​pi_ids= fields.One2many('purchase.order.pi.copy','lc_id', string='Proforma Invoices')
​@api.onchange('pi_ids')
​def _onchange_pi_ids(self):
if self.pi_ids:
order_line=self.pi_ids._create_lc_lines_context(self.pi_ids.order_line)
​self.order_line=order_line



The marked order lines are repeated from PI00006.
頭像
捨棄
最佳答案

Hi, 

We think the issue is occurring because the related records are being created again with the onchange function to resolve this, 

Try changing the initialization of the variable "lines" in function "_create_lc_lines_context" as:


              def _create_lc_lines_context(self, lc_id):                     

​ lines= [(5, 0, 0)]


Hope it helps

頭像
捨棄
作者

It worked.
Thanks for your help

相關帖文 回覆 瀏覽次數 活動
1
1月 19
3953
2
7月 20
10391
0
9月 22
2044
2
8月 19
8454
3
3月 25
935