對於Odoo倉庫模塊,如果質量控制想要將產品轉移到庫存時,我必須檢查是否填寫了所有必填字段。 在這一刻,一切正常,但質量控制的位置目前是硬編碼。這意味着當有人使用另一個庫存地點進行質量控制時,他們必須更改代碼。Odoo使用self.env獲取其他模型的數據
我已經搜索槽Odoo文檔,並且據我所見,新的api我必須使用self.env而不是self.pool.get。 (我添加了舊代碼作爲註釋。) 調試時,似乎stock.warehouse在self.pool中,而不在self.env中(但我猜這可能只是其中一種「Odoo」)。
第二件事是我硬編碼了當前的company_id「1」。 我認爲最好的,如果這也可能是最好的,如果這將是一個變量。
我希望有人能幫我解決這個問題。
在此先感謝
class stock_transfer_details(models.TransientModel):
_inherit = "stock.transfer_details"
@api.one
def do_detailed_transfer(self):
res = super(stock_transfer_details, self).do_detailed_transfer()
# Check if all the required lot additional fields have been filled.
# Else raise warning.
# TODO Replace hardcoded Quality location by database reference
warehouse = self.env("stock.warehouse").search([("company_id", "=", "1")])
# self.pool.get("stock.warehouse").browse(cr, uid, item["wh_qc_stock_loc_id"], context=context)
qc_location = warehouse.wh_qc_stock_loc_id
missing_mandatory_fields = []
if self.picking_source_location_id.id == 14:
item_ids = self.mapped("item_ids")
for item in item_ids:
additional_fields = item.lot_id.mapped("lot_lot_additional_fields")
for field in additional_fields:
if field.lot_additional_fields.mandatory and not field.value:
if item.lot_id.name not in missing_mandatory_fields:
missing_mandatory_fields.append(item.lot_id.name)
if missing_mandatory_fields:
error_message = "All required fields for the serial numbers must be filled! \n"
error_message += "Serial numbers: \n"
for item in missing_mandatory_fields:
error_message += item + "\n"
raise exceptions.Warning(error_message)
return res
再次感謝您的快速響應。我沒有現場pack_move_items,在這種情況下,它不會工作。我還檢查了打開包裝時這個字段是否可用,但這也沒有幫助。 –
好的!所以,在你的舊代碼中,你有一個名爲'item'的字典。你可以在這裏寫下它來自哪裏? – forvas
我不確定你在哪裏看到字典命名的項目。這個代碼中唯一的「item」是我在item_ids中用於item的那個。 –