Ejemplo n.º 1
0
class ProductTemplate(models.Model):
    _inherit = 'product.template'
    division_nprod = fields.Char(string=u'División')
    factory_nprod = fields.Char(string=u'Fabrica')
    world_nprod = fields.Char(string=u'Mundo')
    gif_card_nprod = fields.Boolean(string='Es una tarjeta de ragalo',
                                    default=False,
                                    help='')
    unid_size_nprod = fields.Char(string=u'Unidades de medida')
    unid_size_buy_nprod = fields.Char(string=u'Unidad de medida de compra')
    warrant_prod_sales = fields.Integer(string=u'Garantía')
    term_prod_cli_sales = fields.Integer(string=u'Plazo de entrega al cliente')
    web_cliente_info = fields.Char(string=u'Pagina web del fabricante',
                                   required=True)
    vid_nprod_info = fields.Char(
        string=u'Enlace a video de desmostración del producto(Youtube,etc)',
        required=True)
    available_pdv_sales = fields.Boolean(string=u'Disponible en el Pdv')
    category_pdv_sales = fields.Selection([('EUR', 'EUR'), ('USD', 'USD'),
                                           ('BS', 'BS')],
                                          string=u'Moneda del proveedor')
    for_weight_balance_sales = fields.Boolean(string=u'Para pesar con balamza')
    type_nprod = fields.selection([('1', '1'), ('2', '2'), ('3', '3'),
                                   ('4', '4'), ('5', '5'), ('6', '6'),
                                   ('7', '7'), ('8', '8'), ('9', '9'),
                                   ('10', '10')],
                                  string=u'Communication Skills')
Ejemplo n.º 2
0
class ZooCage(models.Model):
    _name = "zoo.cage"
    _description = "Cage of animal in the zoo"

    name = fields.Many2one(comodel_name='product.product',
                               string="Meal name")
    volume = fields.Float('Volume', required=True)
    meals = fields.selection([
        ('breakfast', 'Breakfast'),
        ('lunch', 'Lunch'),
        ('dinner', 'Dinner'),
        ('super', ' Super')
    ], string='meals', default ='breakfast', required=True)
Ejemplo n.º 3
0
class res_partner(models.Model):
    _inherit = "res.partner"
    _columns = {
                # RUC: Registro Unico del Contribuyente (Panama)
                'ruc': fields.char('RUC', size=45, required=True),
                # DV: Digito verificador
                'dv': fields.char('DV', size=2, required=True),
                # TIPO_PERSONA
                #  1=NATURAL 
                #  2=JURIDICO
                #  3=OTROS
                #  4=EXTRANJERO
                'tipo_persona': fields.selection([('1','NATURAL'),('2','JURIDICO'),('3','OTROS'),('4','EXTRANJERO')],'Tipo Persona',required=True),
                # Concepto Varios a Uno
                #'concepto' : fields.many2one('anexos.conceptos.pa', 'concepto','Anexo Concepto', store=True, readonly=False)
                #'concepto' : fields.many2many('anexos.conceptos.pa','res_partner_anexos_conceptos_pa_rel','partner_id', 'concepto','Concepto de Anexo', store=True, readonly=False)
               }
Ejemplo n.º 4
0
class HrChildren(model.Model):
    """Class to add object of childrens to employee
    """
    _name = "hr.children"

    _order = 'name'

    _columns = {
        'name':
        fields.char('Name', size=64, required=True),
        'date_of_birth':
        fields.date('Date of birth'),
        'schooling':
        fields.selection([('elementary', 'Elementary'),
                          ('high_school', 'High School'),
                          ('preparatory', 'Preparatory'),
                          ('university', 'University')], 'Schooling'),
        'employee_id':
        fields.many2one('hr.employee', 'Employee')
    }
class ProductProductWebServer(models.Model):
    """ Model name: ProductProductWebServer
    """

    _inherit = 'product.product.web.server'

    # -------------------------------------------------------------------------
    # Utility:
    # -------------------------------------------------------------------------
    @api.model
    def get_existence_for_product(self, product):
        """ Return real existence for web site
        """
        stock_quantity = int(product.mx_net_mrp_qty - product.mx_mrp_b_locked)
        # TODO manage q x pack?
        # q_x_pack = product.q_x_pack or 1
        # stock_quantity //= q_x_pack
        if stock_quantity < 0:
            return 0
        return stock_quantity

    @api.model
    def get_category_block_for_publish(self, item, lang):
        """ Get category block for data record WP
        """
        categories = []
        for category in item.wordpress_categ_ids:
            wp_id = eval('category.wp_%s_id' % lang)
            wp_parent_id = eval('category.parent_id.wp_%s_id' % lang)
            if not wp_id:
                continue
            categories.append({'id': wp_id})
            if category.connector_id.wp_all_category and category.parent_id:
                categories.append({'id': wp_parent_id})
        return categories

    # -------------------------------------------------------------------------
    # Button event:
    # -------------------------------------------------------------------------
    @api.multi
    def open_image_list_product(self):
        """
        """
        model_pool = self.env['ir.model.data']
        view_id = model_pool.get_object_reference(
            'wordpress_connector', 'view_product_product_web_server_form')[1]

        return {
            'type': 'ir.actions.act_window',
            'name': _('Image detail'),
            'view_type': 'form',
            'view_mode': 'form,form',
            'res_id': self[0].id,
            'res_model': 'product.product.web.server',
            'view_id': view_id,  # False
            'views': [(view_id, 'form'), (False, 'tree')],
            'domain': [],
            'context': self.env.context,
            'target': 'new',
            'nodestroy': False,
        }

    @api.model
    def wp_clean_code(self, default_code, destination='wp'):
        """ Return default code for Wordpress
        """
        if destination == 'wp':
            return default_code.replace(' ', '&nbsp;')
        else:  # odoo
            return default_code.replace('&nbsp;', ' ')

    @api.model
    def get_wp_price(self, line):
        """ Extract price depend on force, discount and VAT
        """
        product = line.product_id
        if line.force_price:
            price = line.force_price
        else:
            price = product.lst_price * (100.0 -
                                         line.connector_id.discount) / 100.0

        price += line.connector_id.add_vat * price / 100.0
        if price < line.connector_id.min_price:
            price = line.connector_id.min_price

        # ADD approx?
        return price

    @api.multi
    def publish_now(self):
        """ Publish now button
            Used also for more than one elements (not only button click)
            Note all product must be published on the same web server!
        """
        default_lang = 'it'
        log_excel = self.env.context.get('log_excel', False)

        first_proxy = self[0]
        if not first_proxy.connector_id.wordpress:
            _logger.warning('Not a wordpress proxy, call other')
            return super(ProductProductWebServer, self).publish_now()

        # ---------------------------------------------------------------------
        #                         WORDPRESS Publish:
        # ---------------------------------------------------------------------
        _logger.warning('Publish all on wordpress:')
        product_pool = self.env['product.product']
        server_pool = self.env['connector.server']
        # lang_pool = self.env['product.product.web.server.lang']

        wcapi = server_pool.get_wp_connector(first_proxy.connector_id)

        # Context used here:
        # TODO manage image with context
        # context_lang = self.env.context.copy()

        # Read first element only for setup parameters:
        connector = first_proxy.connector_id
        # context_lang['album_id'] = first_proxy.connector_id.album_id.id
        # context['album_id'] = first_proxy.connector_id.album_id.id

        # ---------------------------------------------------------------------
        # Publish image:
        # ---------------------------------------------------------------------
        # TODO (save link)

        # ---------------------------------------------------------------------
        # Publish product (lang management)
        # ---------------------------------------------------------------------
        translation_lang = {}

        # First lang = original, second traslate
        for odoo_lang in ('it_IT', 'en_US'):
            lang = odoo_lang[:2]  # WP lang
            context_lang['lang'] = odoo_lang  # self._lang_db

            for item in self:  # .browse(cr, uid, ids, context=context_lang):

                # Readability:
                product = item.product_id
                default_code = product.default_code or u''
                sku = default_code

                # Description:
                name = item.force_name or product.name or u''
                description = item.force_description or \
                    product.emotional_description or \
                    product.large_description or u''
                short = product.emotional_short_description or name or u''

                price = u'%s' % self.get_wp_price(item)
                # weight = u'%s' % product.weight
                status = 'publish' if item.published else 'private'
                stock_quantity = self.get_existence_for_product(product)
                wp_id = eval('item.wp_%s_id' % lang)
                wp_it_id = item.wp_it_id  # Default product for language
                # fabric, type_of_material

                # -------------------------------------------------------------
                # Images block:
                # -------------------------------------------------------------
                images = []
                for image in item.wp_dropbox_images_ids:
                    dropbox_link = image.dropbox_link
                    if dropbox_link and dropbox_link.startswith('http'):
                        images.append({
                            'src': image.dropbox_link,
                        })

                # -------------------------------------------------------------
                # Category block:
                # -------------------------------------------------------------
                categories = self.get_category_block_for_publish(item, lang)

                # Text data (in lang):
                data = {
                    'name': name,
                    'description': description,
                    'short_description': short,
                    'sku': self.wp_clean_code(sku),  # XXX not needed
                    'lang': lang,
                    # It doesn't update:
                    'categories': categories,
                    'wp_type': item.wp_type,
                }
                if images:
                    data['images'] = images

                if lang == default_lang:
                    # Numeric data:
                    data.update({
                        'type': item.wp_type,
                        # 'sku': self.wp_clean_code(sku),
                        'regular_price': price,
                        # sale_price (discounted)
                        'stock_quantity': stock_quantity,
                        'status': status,
                        'catalog_visibility': 'visible',
                        # catalog  search  hidden

                        # Forced in variant:
                        # 'weight': weight,
                        # 'dimensions': {
                        #   'width': '%s' % product.width,
                        #   'length': '%s' % product.length,
                        #   'height': '%s' % product.height,
                        #   },
                    })

                else:  # Other lang (only translation
                    if not wp_it_id:
                        _logger.error('Product %s without default IT [%s]' %
                                      (lang, default_code))
                        continue

                    # Translation:
                    data.update({
                        'translations': {
                            'it': wp_it_id
                        },
                    })

                # -------------------------------------------------------------
                #                         Update:
                # -------------------------------------------------------------
                if wp_id:
                    try:
                        call = 'products/%s' % wp_id
                        reply = wcapi.put(call, data).json()

                        if log_excel != False:
                            log_excel.append(('put', call, u'%s' % (data, ),
                                              u'%s' % (reply, )))

                        if reply.get('code') in (
                                'product_invalid_sku',
                                'woocommerce_rest_product_invalid_id'):
                            pass  # TODO Manage this case?
                            # wp_id = False # will be created after
                        else:
                            _logger.warning('Product %s lang %s updated!' %
                                            (wp_id, lang))
                    except:
                        # TODO manage this error if present
                        _logger.error('Not updated ID %s lang %s [%s]!' %
                                      (wp_id, lang, data))

                # -------------------------------------------------------------
                #                         Create:
                # -------------------------------------------------------------
                if not wp_id:
                    # Create (will update wp_id from now)
                    try:
                        call = 'products'
                        reply = wcapi.post(call, data).json()
                        if log_excel != False:
                            log_excel.append(('post', call, u'%s' % (data, ),
                                              u'%s' % (reply, )))
                    except:  # Timeout on server:
                        _logger.error('Server timeout: %s' % (data, ))
                        continue

                    try:
                        if reply.get('code') == 'product_invalid_sku':
                            wp_id = reply['data']['resource_id']
                            _logger.error(
                                'Product %s lang %s duplicated [%s]!' %
                                (wp_id, lang, reply))

                        else:
                            wp_id = reply['id']
                            _logger.warning('Product %s lang %s created!' %
                                            (wp_id, lang))
                    except:
                        raise osv.except_osv(
                            _('Error'),
                            _('Reply not managed: %s' % reply),
                        )
                        continue

                    if wp_id:
                        self.write(cr,
                                   uid, [item.id], {
                                       'wp_%s_id' % lang: wp_id,
                                   },
                                   context=context)

                # Save translation of ID (for language product)
                if default_code not in translation_lang:
                    translation_lang[default_code] = {}
                translation_lang[default_code][lang] = (wp_id, name)
        return translation_lang

    # -------------------------------------------------------------------------
    # Function fields:
    # -------------------------------------------------------------------------
    def _get_album_images(self, cr, uid, ids, fields, args, context=None):
        """ Fields function for calculate
        """
        res = {}
        for current in self.browse(cr, uid, ids, context=context):
            server_album_ids = [
                item.id for item in current.connector_id.album_ids
            ]

            res[current.id] = [
                image.id for image in current.product_id.image_ids \
                    if image.album_id.id in server_album_ids]
        return res

    def _get_product_detail_items(self,
                                  cr,
                                  uid,
                                  ids,
                                  fields,
                                  args,
                                  context=None):
        """ Fields function for calculate
        """
        res = {}
        for line in self.browse(cr, uid, ids, context=context):
            res[line.id] = {}

            product = line.product_id
            model = product.model_package_id
            if model:
                res[line.id] = {
                    'pack_l': float(model.box_width),
                    'pack_h': float(model.box_height),
                    'pack_p': float(model.box_depth),
                    'weight': float(model.gross_weight) / 1000.0,
                    'weight_net': float(model.net_weight) / 1000.0,
                    'q_x_pack': float(model.pcs_box),
                    'lst_price': product.lst_price,
                    # pallet dimension
                }
            else:
                res[line.id] = {
                    'pack_l': product.pack_l,
                    'pack_h': product.pack_h,
                    'pack_p': product.pack_p,
                    'weight': product.weight,
                    'weight_net': product.weight_net,
                    'q_x_pack': product.q_x_pack,
                    'lst_price': product.lst_price,
                }
        return res

    wp_it_id = fields.Integer('WP it ID')
    wp_en_id = fields.Integer('WP en ID')
    wordpress_categ_ids = fields.Many2many('product.public.category',
                                           'product_wp_rel', 'product_id',
                                           'category_id', 'Wordpress category')
    # wp_dropbox_images_ids = fields.One2many(
    #    'product.image.file',
    #    compute='_get_album_images',
    #    string='Album images',
    #    )
    wordpress = fields.related('connector_id',
                               'wordpress',
                               type='boolean',
                               string='Wordpress')

    # ---------------------------------------------------------------------
    # Product related/linked fields:
    # ---------------------------------------------------------------------
    model_package_id = fields.Mqny2one('product_id.model_package_id',
                                       readonly=True,
                                       string='Package model')

    pack_l = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='L. Pack',
        multi=True,
    )
    pack_h = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='H. Pack',
        multi=True,
    )
    pack_p = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='P. Pack',
        multi=True,
    )

    weight = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='Gross weight',
        multi=True,
    )
    weight_net = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='NEt weight',
        multi=True,
    )

    lst_price = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='Pricelist',
        multi=True,
    )

    q_x_pack = fields.Float(
        _get_product_detail_items,
        method=True,
        readonly=True,
        type='float',
        string='Q. x Pack',
        multi=True,
    )

    # ---------------------------------------------------------------------
    # Link related to product
    # ---------------------------------------------------------------------
    product_pack_l = fields.Float('product_id.pack_l', string='Pack L prod.')
    product_pack_h = fields.Float('product_id.pack_h', string='Pack H prod.')
    product_pack_p = fields.Float('product_id.pack_p', string='Pack P prod.')

    product_weight = fields.Float('product_id.weight',
                                  string='New weight prod.')
    product_weight_net = fields.Float('product_id.weight_net',
                                      string='Gross weight prod.')

    product_lst_price = fields.Float('product_id.lst_price',
                                     string='Pricelist')
    product_q_x_pack = fields.Float('product_id.q_x_pack',
                                    string='Q x pack prodotto')
    # ---------------------------------------------------------------------

    wp_type = fields.selection([
        ('simple', 'Simple product'),
        ('grouped', 'Grouped product'),
        ('external', 'External product'),
        ('variable', 'Variable product'),
    ], 'Wordpress type')
Ejemplo n.º 6
0
class WebsiteProposal(models.Model):
    _name = 'website_proposal.proposal'
    _rec_name = 'id'

    def _get_default_company(self):
        company_id = self.env['res.users']._get_company(context=context)
        if not company_id:
            raise UserError(_('Error!'), _('There is no default company for the current user!'))
        return company_id

    def _get_res_name(self, name, args):
        res = {}
        for r in self.browse(ids):
            record = self.env[r.res_model].browse(r.res_id)
            res[r.id] = record.name
        return res

    _columns = {
        'res_name': fields.function(_get_res_name, string='Name', type='char'),
        'access_token': fields.char('Security Token', required=True, copy=False),
        'template_id': fields.many2one('website_proposal.template', 'Quote Template', readonly=True),
        'head': fields.text('Html head'),
        'page_header': fields.text('Page header'),
        'website_description': fields.html('Description'),
        'page_footer': fields.text('Page footer'),

        'res_model': fields.char('Model', readonly=True, help="The database object this is attached to"),
        'res_id': fields.integer('Resource ID', readonly=True, help="The record id this is attached to", select=True),
        'sign': fields.binary('Singature'),
        'sign_date': fields.datetime('Signing Date'),
        'signer': fields.binary('Signer'),
        'state': fields.selection([
            ('draft', 'Draft'),
            ('rejected', 'Rejected'),
            ('done', 'Signed'),
        ]),
        'company_id': fields.many2one('res.company', 'Company'),
    }
    _defaults = {
        'access_token': lambda self, cr, uid, ctx={}: str(uuid.uuid4()),
        'company_id': _get_default_company,
        'state': 'draft',
    }

    def open_proposal(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/%s' % (ids[0])
        }

    def edit_proposal(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/%s?enable_editor' % (ids[0])
        }

    def create(self, vals):
        record = self.env[vals.get('res_model']).browse(vals.get('res_id'))

        mako = mako_template_env.from_string(tools.ustr(vals.get('website_description')))
        website_description = mako.render({'record': record})
        website_description = website_description.replace('template-only-', '')

        vals['website_description'] = website_description
        new_id = super(WebsiteProposal, self).create(vals)
        return new_id