示例#1
0
def migrate(cr, version):
    """
    It can be the case that procurement was not installed in the 7.0 database,
    as in 7.0 stock was a dependency of procurement and not the other way
    around like it is in 8.0. So we need to check if we are migrating a
    database in which procurement related stuff needs to be migrated.
    """
    registry = RegistryManager.get(cr.dbname)
    populate_stock_move_fields(cr, registry)
    have_procurement = openupgrade.column_exists(
        cr, 'product_template', openupgrade.get_legacy_name('procure_method'))

    migrate_stock_warehouses(cr, registry)
    migrate_stock_picking(cr, registry)
    migrate_stock_location(cr, registry)

    if have_procurement:
        migrate_stock_warehouse_orderpoint(cr)
        migrate_product_supply_method(cr, registry)
        migrate_procurement_order(cr, registry)

    migrate_stock_qty(cr, registry)
    migrate_stock_production_lot(cr, registry)

    # Initiate defaults before filling.
    openupgrade.set_defaults(cr, registry, default_spec, force=False)

    migrate_product(cr, registry)
    openupgrade.delete_model_workflow(cr, 'stock.picking')
    openupgrade_80.set_message_last_post(
        cr, uid, registry, ['stock.production.lot', 'stock.picking'])
    migrate_move_inventory(cr, registry)
    reset_warehouse_data_ids(cr, registry)
示例#2
0
def migrate(cr, version):
    openupgrade.rename_columns(cr, column_renames)
    openupgrade.rename_xmlids(cr, xmlid_renames)
    initialize_location_inventory(cr)
    openupgrade.rename_tables(cr, [('stock_inventory_move_rel', None)])

    have_procurement = openupgrade.column_exists(
        cr, 'product_template', openupgrade.get_legacy_name('procure_method'))
    if have_procurement:
        swap_procurement_move_rel(cr)
示例#3
0
def migrate(cr, version):
    """
    Run upon a fresh installation because this is a new glue module between
    stock and account in Odoo 8.0.
    Check for ourselves if the migration script applies by checking for a
    specific legacy column that is migrated here and then removed.
    """
    if not openupgrade.column_exists(cr, 'stock_inventory',
                                     openupgrade.get_legacy_name('date_done')):
        return
    pool = pooler.get_pool(cr.dbname)
    inventory_period_id(cr, pool)
    create_properties(cr, pool)
    propagate_invoice_state(cr)
示例#4
0
def migrate_product_valuation(cr, pool):
    """Migrate the product valuation to a property field on product template.
    This field was moved to a new module which is not installed when the
    migration starts and thus not upgraded, which is why we do it here in the
    deferred step.

    This method removes the preserved legacy column upon success, to prevent
    double runs which would be harmful.
    """
    valuation_column = openupgrade.get_legacy_name('valuation')
    if not openupgrade.column_exists(cr, 'product_product', valuation_column):
        return

    cr.execute(
        """
        SELECT id FROM ir_model_fields
        WHERE model = 'product.template' AND name = 'valuation'
        """)
    field_id = cr.fetchone()[0]

    property_obj = pool['ir.property']
    default = 'manual_periodic'  # as per stock_account/stock_account_data.xml

    cr.execute(
        """
        SELECT product_tmpl_id, {column} FROM product_product
        WHERE {column} != %s""".format(column=valuation_column),
        (default,))
    products = cr.fetchall()
    logger.debug(
        "Migrating the valuation field of %s products with non-default values",
        len(products))

    seen_ids = []
    for template_id, value in products:
        if not value or template_id in seen_ids:
            continue
        seen_ids.append(template_id)
        property_obj.create(
            cr, SUPERUSER_ID, {
                'fields_id': field_id,
                'company_id': False,
                'res_id': 'product.template,{}'.format(template_id),
                'name': 'Valuation Property',
                'type': 'selection',
                'value_text': value,
                })

    cr.execute(
        "ALTER TABLE product_product DROP COLUMN {}".format(valuation_column))
示例#5
0
def update_paydays(cr):
    """
    If column paydays exists in account_payment_term then module paydays was
    installed. We must propagate paydays to account_payment_term_line to avoid
    to lose data.
    """
    if not openupgrade.column_exists(cr, 'account_payment_term', 'paydays'):
        return
    openupgrade.logged_query(
        cr, """
        UPDATE account_payment_term_line aptl
        SET paydays = apt.paydays
        FROM account_payment_term apt
        WHERE apt.id = aptl.payment_id
    """)
示例#6
0
def migrate_procurement_order_method(cr, pool):
    """Procurements method: change the supply_method for the matching rule

    Needs to be deferred because the rules are created in the migration
    of stock, purchase and mrp.

    Will only run if stock is installed. Will run after every attempt to
    upgrade, but harmless when run multiple times.
    """

    cr.execute(
        """
        SELECT id FROM ir_module_module
        WHERE name = 'stock' AND state = 'installed'
        AND latest_version = '8.0.1.1'
        """)
    if not cr.fetchone():
        # Only warn if there are traces of stock
        if openupgrade.table_exists(cr, 'stock_move'):
            logger.debug(
                "Stock not installed or not properly migrated, skipping "
                "migration of procurement orders.")
        return

    procure_method_legacy = openupgrade.get_legacy_name('procure_method')
    if not openupgrade.column_exists(
            cr, 'product_template', procure_method_legacy):
        # in this case, there was no migration for the procurement module
        # which can be okay if procurement was not installed in the 7.0 db
        return

    procurement_obj = pool['procurement.order']
    rule_obj = pool['procurement.rule']
    rules = {}
    for rule in rule_obj.browse(
            cr, SUPERUSER_ID,
            rule_obj.search(cr, SUPERUSER_ID, [])):
        rules.setdefault(
            rule.location_id.id, {})[rule.procure_method] = rule.id
        rules.setdefault(rule.location_id.id, {})[rule.action] = rule.id

    cr.execute(
        """
        SELECT pp.id FROM product_product pp, product_template pt
        WHERE pp.product_tmpl_id = pt.id
            AND pt.%s = 'produce'
        """ % openupgrade.get_legacy_name('supply_method'))
    production_products = [row[0] for row in cr.fetchall()]

    cr.execute(
        """
        SELECT id, %s FROM procurement_order
        WHERE rule_id is NULL AND state != %%s
        """ % procure_method_legacy, ('done',))

    procurements = cr.fetchall()
    if len(procurements):
        logger.debug(
            "Trying to find rules for %s procurements", len(procurements))

    for proc_id, procure_method in procurements:
        procurement = procurement_obj.browse(cr, SUPERUSER_ID, proc_id)
        location_id = procurement.location_id.id

        # if location type is internal (presumably stock), then
        # find the rule with this location and the appropriate action,
        # regardless of procure method
        rule_id = False
        action = 'move'  # Default, only for log message
        if procure_method == 'make_to_order':
            if procurement.location_id.usage == 'internal':
                if procurement.product_id.id in production_products:
                    action = 'manufacture'
                else:
                    action = 'buy'
                rule_id = rules.get(location_id, {}).get(action)
            else:
                rule_id = rules.get(location_id, {}).get('make_to_order')
        else:
            rule_id = rules.get(location_id, {}).get('make_to_stock')
        if rule_id:
            procurement.write({'rule_id': rule_id})
        else:
            logger.warn(
                "Procurement order #%s with location %s "
                "has no %s procurement rule with action %s, please create and "
                "assign a new rule for this procurement""",
                procurement.id, procurement.location_id.name,
                procure_method, action)