从哪里默认WH /股票创建?

时间:2017-04-29 16:17:30

标签: openerp odoo-8 odoo-9 odoo-10

我在odoo中查看stock模块的代码。我知道在安装模块时可以使用数据文件创建记录(产品,客户)。我查看库存模块的数据文件,但没有任何记录从WH / Stock创建。

就像这里使用此创建的合作伙伴位置一样。那么从何处创建WH / Stock Location以及如何?

<record id="stock_location_locations_partner" model="stock.location">
    <field name="name">Partner Locations</field>
    <field name="usage">view</field>
    <field name="posz">1</field>
    <field name="company_id"></field>
</record>

2 个答案:

答案 0 :(得分:0)

首次安装库存模块时,从 data / stock_data.yml',',文件而不是xml数据文件创建WH /库存位置,之后每当新的warehosue创建它时,都是从create方法创建的class stock.warehosue。

这是yml数据文件的代码

-
  !python {model: res.partner, id: base.main_partner}: |
    main_warehouse = self.env['stock.warehouse'].browse(ref('warehouse0'))
    self.write({'property_stock_customer':main_warehouse.lot_stock_id.id})    

-
  !python {model: ir.model.data, id: False}: |
    main_warehouse = self.env['stock.warehouse'].browse(ref('warehouse0'))

    #create xml ids for demo data that are widely used in tests or in other codes, for more convenience
    xml_references = [
        {'name': 'stock_location_stock', 'module': 'stock', 'model': 'stock.location', 'res_id': main_warehouse.lot_stock_id.id},
        {'name': 'stock_location_company', 'module': 'stock', 'model': 'stock.location', 'res_id': main_warehouse.wh_input_stock_loc_id.id},
        {'name':'stock_location_output','module':'stock', 'model':'stock.location','res_id':main_warehouse.wh_output_stock_loc_id.id},
        {'name':'location_pack_zone','module':'stock', 'model':'stock.location','res_id':main_warehouse.wh_pack_stock_loc_id.id},
        {'name':'picking_type_internal','module':'stock', 'model':'stock.picking.type','res_id':main_warehouse.int_type_id.id},
        {'name':'picking_type_in','module':'stock', 'model':'stock.picking.type','res_id':main_warehouse.in_type_id.id},
        {'name':'picking_type_out','module':'stock', 'model':'stock.picking.type','res_id':main_warehouse.out_type_id.id},
    ]
    for xml_record in xml_references:
        xml_ids = self.search([('module', '=', xml_record['module']), ('model', '=', xml_record['model']), ('name', '=', xml_record['name'])]).ids
        if not xml_ids:
            self.create(xml_record)
        #avoid the xml id and the associated resource being dropped by the orm by manually making a hit on it
        self._update_dummy(xml_record['model'], xml_record['module'], xml_record['name'])

-
  !python {model: res.company, id: False}: |
    #create the transit location for each company existing
    companies = self.search([('internal_transit_location_id', '=', False)])
    for company in companies:
        company.create_transit_location()

答案 1 :(得分:0)

首次安装库存模块时,创建的WH / Stock位置请参见stock_warehouse.py文件的库存模块中创建方法的代码。请参阅以下代码中的 sub_locations 字典。仅引用使用yml文件分配的xml id。

@api.model
def create(self, vals):
    # create view location for warehouse then create all locations
    loc_vals = {'name': _(vals.get('code')), 'usage': 'view',
                'location_id': self.env.ref('stock.stock_location_locations').id}
    if vals.get('company_id'):
        loc_vals['company_id'] = vals.get('company_id')
    vals['view_location_id'] = self.env['stock.location'].create(loc_vals).id

    def_values = self.default_get(['reception_steps', 'delivery_steps'])
    reception_steps = vals.get('reception_steps',  def_values['reception_steps'])
    delivery_steps = vals.get('delivery_steps', def_values['delivery_steps'])
    sub_locations = {
        'lot_stock_id': {'name': _('Stock'), 'active': True, 'usage': 'internal'},
        'wh_input_stock_loc_id': {'name': _('Input'), 'active': reception_steps != 'one_step', 'usage': 'internal'},
        'wh_qc_stock_loc_id': {'name': _('Quality Control'), 'active': reception_steps == 'three_steps', 'usage': 'internal'},
        'wh_output_stock_loc_id': {'name': _('Output'), 'active': delivery_steps != 'ship_only', 'usage': 'internal'},
        'wh_pack_stock_loc_id': {'name': _('Packing Zone'), 'active': delivery_steps == 'pick_pack_ship', 'usage': 'internal'},
    }
    for field_name, values in sub_locations.iteritems():
        values['location_id'] = vals['view_location_id']
        if vals.get('company_id'):
            values['company_id'] = vals.get('company_id')
        vals[field_name] = self.env['stock.location'].with_context(active_test=False).create(values).id

    # actually create WH
    warehouse = super(Warehouse, self).create(vals)
    # create sequences and picking types
    new_vals = warehouse.create_sequences_and_picking_types()
    warehouse.write(new_vals)  # TDE FIXME: use super ?
    # create routes and push/procurement rules
    route_vals = warehouse.create_routes()
    warehouse.write(route_vals)
    # update partner data if partner assigned
    if vals.get('partner_id'):
        self._update_partner_data(vals['partner_id'], vals.get('company_id'))
    return warehouse