对于Odoo仓库模块,当质量控制想要将产品转移到库存时,我必须检查是否已填写所有必填字段。 此时一切正常,但质量控制的位置目前是硬编码的。这意味着当有人使用另一个库存位置进行质量控制时,他们将不得不更改代码。
我已经通过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
答案 0 :(得分:2)
尝试下一个代码:
for item in self.pack_move_items:
warehouse = self.env['stock.warehouse'].browse(item.wh_qc_stock_loc_id.mapped('id'))
答案 1 :(得分:1)
经过大量的研究,我已经能够弄清楚它是如何工作的。
这是我用来获取当前仓库质量位置的代码:
/// <binding ProjectOpened='default' />
///
// include plug-ins
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var del = require('del');
var config = {
//JavaScript files that will be combined into a jquery bundle
jquerysrc: [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/jquery-validation/dist/jquery.validate.min.js'
],
jquerybundle: 'Scripts/jquery-bundle.min.js'
}
// Synchronously delete the output script file(s)
gulp.task('clean-vendor-scripts', function (cb) {
return del([config.jquerybundle], cb);
});
//Create a jquery bundled file
gulp.task('jquery-bundle', ['clean-vendor-scripts'], function () {
return gulp.src(config.jquerysrc)
.pipe(concat('jquery-bundle.min.js'))
.pipe(gulp.dest('Scripts'));
});
//Set a default tasks
gulp.task('default', ['jquery-bundle'], function () {
});
首先,我会查找员工所在的当前仓库。一旦找到,我只需获取wh_qc_stock_loc_id的值