示例#1
0
class ProductPricelistItem(struct.Csv):
    _from = 'raya_dental_product_pricelist_item.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Int(src='price_version_id', dst='price_version_id'),
        parser.Custom(src='product_tmpl_id', dst='product_tmpl_id',
                      parser='parser_product_tmpl_id'),
        parser.Int(src='min_quantity', dst='min_quantity'),
        parser.Int(src='sequence', dst='sequence'),
        parser.Custom(src='base', dst='base', parser='parser_base'),
        parser.Float(src='price_discount', dst='price_discount'),
        parser.Float(src='price_surcharge', dst='price_surcharge'),
        parser.Float(src='price_round', dst='price_round'),
        parser.Float(src='price_min_margin', dst='price_min_margin'),
        parser.Float(src='price_max_margin', dst='price_max_margin'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Str(src='row', dst='row'),
        parser.Custom(src='migration_key', dst='migration_key',
                      parser='parser_migration_key'),

    ]

    def parser_migration_key(self, value):
        value = value.strip()
        versions = self.env['product.pricelist'].search([
            ('migration_key', '=', value)])
        if versions:
            self.record.price_version_id = versions[0].id
            self.record.migration_key = value
        else:
            self.record.price_version_id = None
            self.record.migration_key = value

    def parser_product_tmpl_id(self, value):
        value = value.strip()
        templates = self.env['product.template'].search([
            ('default_code', 'like', value)])
        if templates:
            self.record.product_tmpl_id = templates[0].id
            self.record.name = templates[0].name
        else:
            self.record.product_tmpl_id = None

    def parser_base(self, value):
        value = value.strip()
        self.record.base = 1

    def to(self):
        for item in self.read():  # (count=200):
            try:
                i = self.env['product.pricelist.item'].create(item.dict())
            except Exception as e:
                _log.error('User data %s' % item.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('PriceItem row=%s imported with id=%s' % (
                item.row, i.id))
示例#2
0
class PartnersBank(struct.Csv):
    _from = 'raya_joyeria_partner_bank.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Str(src='partner_id', dst='bank_name'),
        parser.Str(src='state', dst='state'),
        parser.Custom(src='country', dst='country_id',
                      parser='parser_country'),
        parser.Custom(src='acc_number',
                      dst='acc_number',
                      parser='parser_acc_number'),
        parser.Str(src='bank_bic', dst='bank_bic'),
        parser.Custom(src='partner_id',
                      dst='partner_id',
                      parser='parser_partner'),
    ]

    def parser_country(self, value):
        value = value.strip()
        countrys = self.env['res.country'].search([('code', '=', value)])
        if countrys:
            self.record.acc_country_id = countrys[0].id or None
        else:
            self.record.acc_country_id = None

    def parser_partner(self, value):
        value = value.strip()
        partners = self.env['res.partner'].search([('ref', '=', value)])
        if partners:
            self.record.partner_id = partners[0].id
        else:
            self.record.partner_id = None

    def parser_acc_number(self, value):
        value = value.strip()
        cc_code = value[4:8]
        banks = self.env['res.bank'].search([('code', '=', cc_code)])
        self.record.bank = banks and banks[0].id or None,
        self.record.bank_name = banks and [banks[0].name][0] or '',
        self.record.acc_country_id = banks and banks[0].country.id or None,
        self.record.acc_number = value

    def to(self):
        for bank_account in self.read():  # (count=200):
            try:
                bc = self.env['res.partner.bank'].create(bank_account.dict())
            except Exception as e:
                _log.error('Bank data %s' % bank_account.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info(
                'Bank Account "%s" imported with id %s partner %s' %
                (bank_account.acc_number, bc.id, bank_account.partner_id))
示例#3
0
class Partner(struct.Csv):
    _from = 'raya_dental_partner.txt'
    _first_row_titles = True
    _default_record = {
    }
    _initialized = False

    _map = [
        parser.Str(src='ref', dst='ref'),
        parser.Custom(src='property_product_pricelist',
                      dst='property_product_pricelist',
                      parser='parser_pricelist_sale'),
        parser.Custom(src='property_product_pricelist_purchase',
                      dst='property_product_pricelist_purchase',
                      parser='parser_pricelist_purchase'),
    ]

    def parser_pricelist_sale(self, value):
        value = value.strip()
        if value == '':
            self.record.property_product_pricelist = \
                self.env.ref('product.list0').id
        else:
            pricelist = self.env['product.pricelist'].search([
                ('migration_key', '=', value)])
            self.record.property_product_pricelist = \
                pricelist and pricelist[0].id

    def parser_pricelist_purchase(self, value):
        value = value.strip()
        if value == "":
            self.record.property_product_pricelist_purchase = \
                self.env.ref('purchase.list0').id
        else:
            pricelist = self.env['product.pricelist'].search([
                ('migration_key', '=', value)])
            self.record.property_product_pricelist_purchase = \
                pricelist and pricelist[0].id

    def to(self):
        for values in self.read():  # (count=200):

            partner = self.env['res.partner'].search([
                ('ref', '=', values.ref)])
            if partner:
                try:
                    partner.write({
                        'property_product_pricelist':
                            values.property_product_pricelist})
                except Exception as e:
                    _log.error('PriceList data %s' % partner.dict())
                    _log.error('With errors: %s' % e)
                    raise
            _log.info('Partner Pricelist update "%s" ' % (values))
示例#4
0
class Contact(struct.Csv):
    _from = 'raya_joyeria_partner_contact.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Custom(src='ref', dst='parent_id', parser='parser_parent'),
        parser.Str(src='type', dst='type'),
        parser.Str(src='name', dst='name'),
        parser.Str(src='function', dst='function'),
        parser.Str(src='street', dst='street'),
        parser.Str(src='city', dst='city'),
        parser.Custom(src='zip', dst='zip', parser='parser_zip'),
        parser.Str(src='phone', dst='phone'),
        parser.Str(src='mobile', dst='mobile'),
        parser.Str(src='email', dst='email'),
        parser.Date(src='date', dst='date'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Str(src='row', dst='row'),
    ]

    def parser_parent(self, value):
        value = value.strip()
        parents = self.env['res.partner'].search([('ref', '=', value)])
        if parents:
            self.record.parent_id = parents[0].id
        else:
            self.record.parent_id = None

    def parser_zip(self, value):
        value = value.strip()
        zips = self.env['res.better.zip'].search([('name', '=', value)])
        if zips:
            self.record.zip_id = zips[0].id or None
            self.record.zip = zips[0].name or None
            self.record.city = zips[0].city or None
            self.record.state_id = zips[0].state_id.id or None
            self.record.country_id = zips[0].country_id.id or None
        else:
            self.record.zip_id = None
            self.record.state_id = None
            self.record.country_id = None

    def to(self):
        for contact in self.read():  # (count=200):
            try:
                c = self.env['res.partner'].create(contact.dict())
            except Exception as e:
                _log.error('User data %s' % contact.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('Contact "%s" imported with id %s' %
                      (contact.name, c.id))
示例#5
0
class ProductCategory(struct.Csv):
    _from = 'raya_dental_product_category.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Str(src='name', dst='name'),
        parser.Custom(src='parent_id', dst='parent_id',
                      parser='parser_parent'),
        parser.Str(src='type', dst='type'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Str(src='row', dst='row'),
        parser.Str(src='odoo_ext_id', dst='migration_key'),
    ]

    def parser_parent(self, value):
        value = value.strip()
        categorys = self.env['product.category'].search([('migration_key',
                                                          'ilike', value)])
        if categorys:
            self.record.parent_id = categorys[0].id
        else:
            self.record.parent_id = None

    def to(self):
        for category in self.read():  # (count=200):
            try:
                c = self.env['product.category'].create(category.dict())
            except Exception as e:
                _log.error('Category data %s' % category.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('Category "%s" imported with id %s' %
                      (category.name, c.id))
示例#6
0
class ProductPricelist(struct.Csv):
    _from = 'raya_dental_product_pricelist.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Custom(src='name', dst='name', parser='parser_name'),
        parser.Custom(src='type', dst='type', parser='parser_type'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Str(src='row', dst='row'),
        parser.Str(src='migration_key', dst='migration_key'),
    ]

    def parser_name(self, value):
        value = value.strip()
        value = value.capitalize()
        self.record.name = value

    def parser_type(self, value):
        value = value.strip()
        self.record.type = value

    def to(self):
        for pricelist in self.read():  # (count=200):
            try:
                pl = self.env['product.pricelist'].create(pricelist.dict())
                data = {
                    'name': pricelist.name,
                    'pricelist_id': pl.id}
                version = self.env['product.pricelist.version'].create(data)
                _log.info(
                    'Pricelist "%s" imported with id %s version id %s' % (
                        pricelist.name, pl.id, version.id))
            except Exception as e:
                _log.error('Pricelist %s' % pricelist.dict())
                _log.error('With errors: %s' % e)
                raise
示例#7
0
class StockInventoryLne(struct.Csv):
    # _from = 'raya_dental_product_inventory.txt'
    _from = 'raya_joyeria_product_inventory.txt'
    _first_row_titles = True
    _default_record = {}
    _initialized = False

    _map = [
        parser.Custom(src='ref', dst='product_id', parser='parser_product'),
        parser.Float(src='quantity', dst='product_qty'),
    ]

    def parser_product(self, value):
        value = value.strip()
        products = self.env['product.template'].search([('default_code', '=',
                                                         value)])
        if products:
            self.record.product_id = products[0].id or None

    def to(self):

        inventory_data = {
            'name': 'Carga Inventario inicial',
            'date': '2016-01-31',
        }
        inventory = self.env['stock.inventory'].create(inventory_data)
        for values in self.read():  # (count=200):
            if not values.product_id:
                continue
            if values.product_qty < 0:
                continue
            values.inventory_id = inventory.id
            values.location_id = inventory.location_id.id
            try:
                i = self.env['stock.inventory.line'].create(values.dict())
            except Exception as e:
                _log.error('Inventory data %s' % values.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('InventoryLine "%s" imported with id %s' %
                      (values.product_id, i.id))
示例#8
0
class ProductTemplate(struct.Csv):
    _from = 'raya_dental_product.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Str(src='default_code', dst='default_code'),
        parser.Str(src='name', dst='name'),
        parser.Str(src='type', dst='type'),
        parser.Custom(src='product_brand_id',
                      dst='product_brand_id',
                      parser='parser_product_brand'),
    ]

    def parser_product_brand(self, value):
        value = value.strip()
        brands = self.env['product.brand'].search([('name', '=', value)])
        if brands:
            self.record.product_brand_id = brands[0].id
        else:
            self.record.product_brand_id = None
            print value

    def to(self):
        for product in self.read():  # (count=200):
            product_id = self.env['product.template'].search([
                ('migration_key', '=', product.default_code)
            ])
            try:
                product_id.write(product.dict())
            except Exception as e:
                _log.error('Product data %s' % product.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('Product "%s" updated with id %s' %
                      (product_id.name, product.product_brand_id))
示例#9
0
class ProductTemplate(struct.Csv):
    _from = 'raya_dental_product.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Custom(src='purchase_ok',
                      dst='purchase_ok',
                      parser='parser_boolean'),
        parser.Custom(src='sale_ok', dst='sale_ok', parser='parser_boolean'),
        parser.Str(src='default_code', dst='default_code'),
        parser.Str(src='name', dst='name'),
        parser.Str(src='type', dst='type'),
        parser.Str(src='categ_id', dst='categ_id', parser='parser_categ'),
        parser.Str(src='cost_method', dst='cost_method'),
        parser.Custom(src='uom_id', dst='uom_id', parser='parser_uom_id'),
        parser.Custom(src='uom_po_id',
                      dst='uom_po_id',
                      parser='parser_uom_po_id'),
        parser.Float(src='list_price', dst='list_price'),
        parser.Float(src='standard_price', dst='standard_price'),
        parser.Str(src='route_order', dst='route_order'),
        parser.Str(src='route_manufacture', dst='route_manufacture'),
        parser.Custom(src='route_purchase',
                      dst='route_ids',
                      parser='parser_route_ids'),
        parser.Int(src='sale_delay', dst='sale_delay'),
        parser.Float(src='weight', dst='weight'),
        parser.Float(src='weight_net', dst='weight_net'),
        parser.Float(src='volume', dst='volume'),
        parser.Custom(src='property_account_income',
                      dst='property_account_income',
                      parser='parser_property_account_income'),
        parser.Custom(src='property_account_expense',
                      dst='property_account_expense',
                      parser='parser_property_account_expense'),
        parser.Custom(src='taxes_id', dst='taxes_id',
                      parser='parser_taxes_id'),
        parser.Custom(src='supplier_taxes_id',
                      dst='supplier_taxes_id',
                      parser='parser_supplier_taxes_id'),
        parser.Custom(src='track_incoming',
                      dst='track_incoming',
                      parser='parser_track_incoming'),
        parser.Custom(src='track_outgoing',
                      dst='track_outgoing',
                      parser='parser_track_outgoing'),
        parser.Custom(src='track_production',
                      dst='track_production',
                      parser='parser_track_production'),
        parser.Str(src='loc_rack', dst='loc_rack'),
        parser.Str(src='loc_row', dst='loc_row'),
        parser.Str(src='loc_row', dst='loc_row'),
        parser.Str(src='loc_case', dst='loc_case'),
        parser.Custom(src='available_in_pos',
                      dst='available_in_pos',
                      parser='parser_boolean'),
        parser.Str(src='description', dst='description'),
        parser.Str(src='description_sale', dst='description_sale'),
        parser.Int(src='produce_delay', dst='produce_delay'),
        parser.Float(src='unidadesxembase', dst='product_qty_package'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Custom(src='product_brand_id',
                      dst='product_brand_id',
                      parser='parser_product_brand'),
        parser.Custom(src='default_code',
                      dst='migration_key',
                      parser='parser_migration_key'),
        parser.Str(src='row', dst='row'),
    ]

    def parser_boolean(self, value):
        value = value.strip()
        if value == 'S':
            return True
        else:
            return False

    def parser_categ(self, value):
        value = value.strip()
        categorys = self.env['product.category'].search([('migration_key',
                                                          'ilike', value)])
        if categorys:
            self.record.categ_id = categorys[0].id
        else:
            self.record.categ_id = 1

    def parser_uom_id(self, value):
        value = value.strip()
        uoms = self.env['product.uom'].search([('name', '=', value)])
        if uoms:
            self.record.uom_id = uoms[0].id
        else:
            self.record.uom_id = 1

    def parser_uom_po_id(self, value):
        value = value.strip()
        uoms = self.env['product.uom'].search([('name', '=', value)])
        if uoms:
            self.record.uom_po_id = uoms[0].id
        else:
            self.record.uom_po_id = 1

    def parser_route_ids(self, value):
        value = value.strip()
        route_ids = []
        if value == 'S':
            buy_id = self.env['stock.location.route'].search([('name', 'ilike',
                                                               'buy')])
            route_ids.append(buy_id[0].id or None)
        elif self.record.route_manufacture == 'S':
            manufactures = self.env['stock.location.route'].search([
                ('name', 'ilike', 'manufacture')
            ])
            route_ids.append(manufactures[0].id or None)
        elif self.record.route_order == 'S':
            orders = self.env['stock.location.route'].search([('name', 'ilike',
                                                               'pedido')])
            route_ids.append(orders[0].id or None)
        self.record.route_ids = [(6, 0, route_ids)] or None

    def parser_taxes_id(self, value):
        value = value.strip()
        taxes = self.env['account.tax'].search([('description', '=', value)])
        if taxes:
            self.record.taxes_id = [(6, 0, [taxes[0].id])]
        else:
            self.record.taxes_id = None

    def parser_supplier_taxes_id(self, value):
        value = value.strip()
        taxes = self.env['account.tax'].search([('description', '=', value)])
        if taxes:
            self.record.supplier_taxes_id = [(6, 0, [taxes[0].id])]
        else:
            self.record.supplier_taxes_id = None

    def parser_property_account_income(self, value):
        value = value.strip()
        accounts = self.env['account.account'].search([('code', '=', value)])
        if accounts:
            self.record.property_account_income = accounts[0].id
        else:
            self.record.property_account_income = None

    def parser_property_account_expense(self, value):
        value = value.strip()
        accounts = self.env['account.account'].search([('code', '=', value)])
        if accounts:
            self.record.property_account_expense = accounts[0].id
        else:
            self.record.property_account_expense = None

    def parser_track_incoming(self, value):
        value = value.strip()
        if value == 'S':
            self.record.track_incoming = True
        else:
            self.record.track_incoming = False

    def parser_track_outgoing(self, value):
        value = value.strip()
        if value == 'S':
            self.record.track_outgoing = True
        else:
            self.record.track_outgoing = False

    def parser_track_production(self, value):
        value = value.strip()
        if value == 'S':
            self.record.track_production = True
        else:
            self.record.track_production = False

    def parser_migration_key(self, value):
        self.record.migration_key = self.record.default_code.strip() or None

    def parser_product_brand(self, value):
        value = value.strip()
        brands = self.env['product.brand'].search([('name', 'like', value)])
        if brands:
            self.record.product_brand_id = brands[0].id
        else:
            self.record.product_brand_id = None

    def to(self):
        for product in self.read():  # (count=200):
            try:
                p = self.env['product.template'].create(product.dict())
            except Exception as e:
                _log.error('Product data %s' % product.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('Product "%s" imported with id %s' %
                      (product.name, p.id))
示例#10
0
class Partner(struct.Csv):

    _PAY_MODE = {
        "10": "Giro",
        "15": "Giro",
        "1G": "Giro",
        "1V": "Giro",
        "2G": "Giro",
        "3G": "Giro",
        "4G": "Giro",
        "5V": "Giro",
        "90": "Giro",
        "AL": "A La Vista +1000E x2G",
        "AV": "A La Vista",
        "CO": "Recibo",
        "CR": "ContraReembolso",
        "CX": "[*] Efectivo",
        "DB": "Domiciliado",
        "EF": "Efectivo",
        "EM": "eMail",
        "ET": "Talon/Cheque",
        "F0": "Financiado",
        "GI": "Giro Postal",
        "TA": "Pagare",
        "TB": "Transferencia CajaSur",
        "TR": "Transferencia Santander",
        "TV": "Tarjeta Credito",
    }
    _PAY_TERM = {
        "10": "39 Dias",
        "15": "15 Dias",
        "1G": "30 Dias",
        "1V": "60 Dias",
        "2G": "30/60 Dias",
        "3G": "30/60/90 Dias",
        "4G": "30/60/90/120 Dias",
        "5V": "30/60/90/120/180 Dias",
        "90": "90 Dias",
        "AL": "mediato",
        "AV": "mediato",
        "CO": "mediato",
        "CR": "mediato",
        "CX": "mediato",
        "DB": "5 Dias",
        "EF": "mediato",
        "EM": "mediato",
        "ET": "mediato",
        "F0": "12 Meses",
        "GI": "mediato",
        "TA": "mediato",
        "TB": "mediato",
        "TR": "mediato",
        "TV": "mediato"
    }

    _from = 'raya_joyeria_partner.txt'
    _first_row_titles = True
    _default_record = {
        'is_company': True,
        'vat_subjected': True,
        'comment': '',
    }
    _initialized = False

    _map = [
        parser.Custom(src='customer', dst='customer', parser='parser_boolean'),
        parser.Custom(src='supplier', dst='supplier', parser='parser_boolean'),
        parser.Str(src='ref', dst='ref'),
        parser.Str(src='name', dst='name'),
        parser.Str(src='comercial', dst='comercial'),
        parser.Custom(src='category_id',
                      dst='category_id',
                      parser='parser_category_id'),
        parser.Vat(src='vat', dst='vat'),
        parser.Str(src='street', dst='street'),
        parser.Str(src='city', dst='city'),
        parser.Str(src='state_id', dst='state_id'),
        parser.Str(src='country', dst='country_id'),
        parser.Custom(src='zip', dst='zip', parser='parser_zip'),
        parser.Str(src='phone', dst='phone'),
        parser.Str(src='mobile', dst='mobile'),
        parser.Str(src='fax', dst='fax'),
        parser.Str(src='email', dst='email'),
        parser.Str(src='web', dst='website'),
        parser.Date(src='date', dst='date'),
        parser.Custom(src='user_id', dst='user_id', parser='parser_user_id'),
        parser.Custom(src='property_account_position',
                      dst='property_account_position',
                      parser='parser_property_account_position'),
        parser.Custom(src='property_account_receivable',
                      dst='property_account_receivable',
                      parser='parser_property_account_receivable'),
        parser.Custom(src='customer_payment_mode_code',
                      dst='customer_payment_mode',
                      parser='parser_customer_payment_mode'),
        parser.Float(src='credit', dst='credit'),
        parser.Custom(src='property_account_payable',
                      dst='property_account_payable',
                      parser='parser_property_account_payable'),
        parser.Custom(src='supplier_payment_mode_code',
                      dst='supplier_payment_mode',
                      parser='parser_supplier_payment_mode'),
        parser.Custom(src='comment', dst='comment', parser='parser_comment'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Str(src='row', dst='row'),
    ]

    def parser_comment(self, value):
        value = value.strip()
        self.record.comment = value or ''

    def parser_boolean(self, value):
        value = value.strip()
        if value == 'S':
            return True
        else:
            return False

    def parser_category_id(self, value):
        value = value.strip()
        categorys = value.split(',')
        result = []
        for category in categorys:
            category_ids = self.env['res.partner.category'].search([
                ('name', '=', category)
            ])
            if category_ids:
                result.append(category_ids[0].id)
                self.record.category_id = categorys[0]
        if result:
            self.record.category_id = [(6, 0, result)]
        else:
            self.record.category_id = None

    def parser_user_id(self, value):
        value = value.strip()
        users = self.env['res.users'].search([('name', '=', value)])
        if users:
            self.record.user_id = users[0]
        else:
            self.record.user_id = None

    def parser_zip(self, value):
        value = value.strip()
        zips = self.env['res.better.zip'].search([('name', '=', value)])
        if zips:
            self.record.zip_id = zips[0].id or None
            self.record.zip = zips[0].name or None
            self.record.city = zips[0].city or None
            self.record.state_id = zips[0].state_id.id or None
            self.record.country_id = zips[0].country_id.id or None
        else:
            self.record.comment += 'Direccion\n=========\n%s\n%s \n' % (
                self.record.get('street', ''), value)
            self.record.comment += 'Codigo postal\n=========\n%s\n%s \n' % (
                self.record.get('zip', ''), value)
            self.record.comment += 'Poblacion\n=========\n%s\n%s \n' % (
                self.record.get('city', ''), value)
            self.record.comment += 'Provincia\n=========\n%s\n%s \n' % (
                self.record.get('state_id', ''), value)
            self.record.comment += 'Pais\n=========\n%s\n%s \n' % (
                self.record.get('country_id', ''), value)
            self.record.zip_id = None
            self.record.state_id = None
            self.record.country_id = None

    def parser_property_account_position(self, value):
        value = value.strip()
        account_positions = self.env['account.fiscal.position'].search([
            ('name', '=', value)
        ])
        if account_positions:
            self.record.property_account_position = account_positions[0].id
        else:
            self.record.comment += 'Posicion Fiscal\n=========\n%s\n%s \n' % (
                self.record.get('property_account_position', ''), value)

    def parser_property_account_receivable(self, value):
        value = value.strip()
        if value == "":
            value = '430000000'
        accounts = self.env['account.account'].search([('code', '=', value)])
        if accounts:
            self.record.property_account_receivable = accounts[0].id
        else:
            self.record.property_account_receivable = None

    def parser_property_account_payable(self, value):
        value = value.strip()
        if value == "":
            value = '400000000'
        accounts = self.env['account.account'].search([('code', '=', value)])
        if accounts:
            self.record.property_account_payable = accounts[0].id
        else:
            self.record.property_account_payable = None

    def parser_customer_payment_mode(self, value):
        value = value.strip()
        if value:
            mode = self._PAY_MODE[value] or None
            term = self._PAY_TERM[value] or None
            payment_modes = self.env['payment.mode'].search([('name', '=',
                                                              mode)])
            payment_terms = self.env['account.payment.term'].search([
                ('name', '=', term)
            ])
            if payment_modes:
                self.record.customer_payment_mode = payment_modes[0].id
            else:
                self.record.customer_payment_mode = None

            if payment_terms:
                self.record.property_payment_term = payment_terms[0].id
            else:
                self.record.property_payment_term = None

    def parser_supplier_payment_mode(self, value):
        value = value.strip()
        if value:
            mode = self._PAY_MODE[value] or None
            term = self._PAY_TERM[value] or None

            payment_modes = self.env['payment.mode'].search([('name', '=',
                                                              mode)])
            payment_terms = self.env['account.payment.term'].search([
                ('name', '=', term)
            ])

            if payment_modes:
                self.record.supplier_payment_mode = payment_modes[0].id
            else:
                self.record.supplier_payment_mode = None
            if payment_terms:
                self.record.property_supplier_payment_term = payment_terms[
                    0].id
            else:
                self.record.property_supplier_payment_term = None

    def to(self):
        for partner in self.read():  # (count=200):
            try:
                p = self.env['res.partner'].create(partner.dict())
            except Exception as e:
                _log.error('User data %s' % partner.dict())
                _log.error('With errors: %s' % e)
                raise
            _log.info('Partner "%s" imported with id %s' %
                      (partner.name, p.id))
示例#11
0
class ProductSupplierInfo(struct.Csv):
    _from = 'raya_joyeria_supplierinfo.txt'
    _first_row_titles = True
    _initialized = False

    _map = [
        parser.Custom(src='product_id',
                      dst='product_tmpl_id',
                      parser='parser_product_id'),
        parser.Custom(src='partner_id', dst='name',
                      parser='parser_partner_id'),
        parser.Custom(src='product_code',
                      dst='product_code',
                      parser='parser_product_code'),
        parser.Custom(src='product_name',
                      dst='product_name',
                      parser='parser_product_name'),
        parser.Str(src='filename', dst='filename'),
        parser.Str(src='sheetname', dst='sheetname'),
        parser.Str(src='row', dst='row'),
        parser.Str(src='product_id', dst='migration_key'),
    ]

    def parser_product_id(self, value):
        value = value.strip()
        products = self.env['product.template'].search([('default_code',
                                                         'like', value)])
        if products:
            self.record.product_tmpl_id = products[0].id
        else:
            self.record.product_tmpl_id = None

    def parser_partner_id(self, value):
        value = value.strip()
        partners = self.env['res.partner'].search([('supplier', '=', True),
                                                   ('ref', 'like', value)])
        if partners:
            self.record.name = partners[0].id
        else:
            self.record.name = None

    def parser_product_code(self, value):
        value = value.strip()
        if value == '':
            self.record.product_code = None
        else:
            self.record.product_code = value

    def parser_product_name(self, value):
        value = value.strip()
        if value == '':
            self.record.product_name = None
        else:
            self.record.product_name = value

    def to(self):
        for supplierinfo in self.read():  # (count=200):

            try:
                if supplierinfo.name and supplierinfo.product_tmpl_id:
                    sp = self.env['product.supplierinfo'].create(
                        supplierinfo.dict())
                    _log.info('Reg.Info "%s" imported with id %s' %
                              (supplierinfo.name, sp.id))
                else:
                    _log.info('Reg.Info "%s" NOT IMPORTED with row %s' %
                              (supplierinfo.name, supplierinfo.row))
            except Exception as e:
                _log.error('Reg.Info %s' % supplierinfo.dict())
                _log.error('With errors: %s' % e)
                raise