示例#1
0
class res_partner(osv.osv):
    _inherit = 'res.partner'
    _columns = {
        'sale_warn':
        fields.selection(WARNING_MESSAGE,
                         'Sales Order',
                         help=WARNING_HELP,
                         required=True),
        'sale_warn_msg':
        fields.text('Message for Sales Order'),
        'purchase_warn':
        fields.selection(WARNING_MESSAGE,
                         'Purchase Order',
                         help=WARNING_HELP,
                         required=True),
        'purchase_warn_msg':
        fields.text('Message for Purchase Order'),
        'picking_warn':
        fields.selection(WARNING_MESSAGE,
                         'Stock Picking',
                         help=WARNING_HELP,
                         required=True),
        'picking_warn_msg':
        fields.text('Message for Stock Picking'),
        'invoice_warn':
        fields.selection(WARNING_MESSAGE,
                         'Invoice',
                         help=WARNING_HELP,
                         required=True),
        'invoice_warn_msg':
        fields.text('Message for Invoice'),
    }
    _defaults = {
        'sale_warn': 'no-message',
        'purchase_warn': 'no-message',
        'picking_warn': 'no-message',
        'invoice_warn': 'no-message',
    }
示例#2
0
class product_template(osv.osv):
    _inherit = 'product.template'

    _columns = {
        'type':
        fields.selection(
            [('adjust', 'Adjust concept'), ('consu', 'Consumable'),
             ('service', 'Service')],
            'Product Type',
            required=True,
            help=
            "Adjust concept are items to be incremented in the client account by invoice errors, interest or other reasons, consumable are product where you don't manage stock, a service is a non-material product provided by a company or an individual."
        ),
    }
示例#3
0
class product_product(osv.osv):
    _inherit = 'product.template'
    _columns = {
        'sale_line_warn':
        fields.selection(WARNING_MESSAGE,
                         'Sales Order Line',
                         help=WARNING_HELP,
                         required=True),
        'sale_line_warn_msg':
        fields.text('Message for Sales Order Line'),
        'purchase_line_warn':
        fields.selection(WARNING_MESSAGE,
                         'Purchase Order Line',
                         help=WARNING_HELP,
                         required=True),
        'purchase_line_warn_msg':
        fields.text('Message for Purchase Order Line'),
    }

    _defaults = {
        'sale_line_warn': 'no-message',
        'purchase_line_warn': 'no-message',
    }
示例#4
0
class magento_backend(orm.Model):

    _name = 'magento.backend'
    _inherit = 'magento.backend'

    def _select_product_active(self, cr, uid, context=None):
        return [('nothing', 'do nothing in Odoo'),
                ('disable', 'disable in Odoo'),
                ('no_sale', 'disable sale option'),
                ('no_sale_no_purchase', 'disable sale & purchase option')]

    _columns = {
        'product_active': fields.selection(
            _select_product_active,
            string='Handle disable products',
            required=True),
    }

    _defaults = {
        'product_active': 'disable',
    }
class aeroo_remove_print_button(osv.osv_memory):
    '''
    Remove Print Button
    '''
    _name = 'aeroo.remove_print_button'
    _description = 'Remove print button'

    def default_get(self, cr, uid, fields_list, context=None):
        values = {}

        report = self.pool.get(context['active_model']).browse(
            cr, uid, context['active_id'], context=context)
        if report.report_wizard:
            act_win_obj = self.pool.get('ir.actions.act_window')
            act_win_ids = act_win_obj.search(
                cr,
                uid, [('res_model', '=', 'aeroo.print_actions')],
                context=context)
            for act_win in act_win_obj.browse(cr,
                                              uid,
                                              act_win_ids,
                                              context=context):
                act_win_context = eval(act_win.context, {})
                if act_win_context.get('report_action_id') == report.id:
                    values['state'] = 'remove'
                    break
            else:
                values['state'] = 'no_exist'
        else:
            irval_mod = self.pool.get('ir.values')
            ids = irval_mod.search(
                cr, uid, [('value', '=', report.type + ',' + str(report.id))])
            if not ids:
                values['state'] = 'no_exist'
            else:
                values['state'] = 'remove'

        return values

    def do_action(self, cr, uid, ids, context):
        this = self.browse(cr, uid, ids[0], context=context)
        report = self.pool.get(context['active_model']).browse(
            cr, uid, context['active_id'], context=context)
        if report.report_wizard:
            report._unset_report_wizard()
        irval_mod = self.pool.get('ir.values')
        event_id = irval_mod.search(
            cr, uid,
            [('value', '=', 'ir.actions.report,%d' % context['active_id'])])[0]
        res = irval_mod.unlink(cr, uid, [event_id])
        this.write({'state': 'done'})
        return _reopen(self, this.id, this._model)

    _columns = {
        'state':
        fields.selection([
            ('remove', 'Remove'),
            ('no_exist', 'Not Exist'),
            ('done', 'Done'),
        ],
                         'State',
                         index=True,
                         readonly=True),
    }
class report_aeroo_import(osv.osv_memory):
    _name = 'aeroo.report_import'
    _description = 'Aeroo report import wizard'

    _columns = {
        'name':
        fields.char('Name', size=64),
        'file':
        fields.binary('Aeroo report file', filters='*.aeroo', required=True),
        'info':
        fields.text('Info', readonly=True),
        'state':
        fields.selection([
            ('draft', 'Draft'),
            ('info', 'Info'),
            ('done', 'Done'),
        ],
                         'State',
                         index=True,
                         readonly=True),
    }

    def default_get(self, cr, uid, fields_list, context=None):
        values = {'state': 'draft'}
        default_ids = context.get('default_ids')
        if default_ids:
            this = self.read(cr,
                             uid,
                             default_ids, ['name', 'state', 'file', 'info'],
                             context=context)[0]
            del this['id']
            values.update(this)
        return values

    def install_report(self, cr, uid, ids, context=None):
        report_obj = self.pool.get('ir.actions.report')
        this = self.browse(cr, uid, ids[0], context=context)
        if report_obj.search(cr,
                             uid, [('report_name', '=', this.name)],
                             context=context):
            raise osv.except_osv(
                _('Warning!'),
                _('Report with service name "%s" already exist in system!') %
                this.name)
        fd = StringIO()
        fd.write(base64.decodestring(this.file))
        fd.seek(0)
        convert_xml_import(cr, 'report_aeroo', fd, {}, 'init', noupdate=True)
        fd.close()
        self.write(cr, uid, ids, {'state': 'done'}, context=context)
        report_id = report_obj.search(cr,
                                      uid, [('report_name', '=', this.name)],
                                      context=context)[-1]
        report = report_obj.browse(cr, uid, report_id, context=context)
        event_id = self.pool.get('ir.values').set_action(
            cr, uid, report.report_name, 'client_print_multi', report.model,
            'ir.actions.report,%d' % report_id)
        if report.report_wizard:
            report._set_report_wizard(report.id)

        mod_obj = self.pool.get('ir.model.data')
        act_obj = self.pool.get('ir.actions.act_window')

        mod_id = mod_obj.search(
            cr, uid, [('name', '=', 'action_aeroo_report_xml_tree')])[0]
        res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id']
        act_win = act_obj.read(cr, uid, res_id, [])
        act_win['domain'] = [('id', '=', report_id)]
        return act_win

    def next(self, cr, uid, ids, context=None):
        this = self.browse(cr, uid, ids[0], context=context)
        file_data = base64.decodestring(this.file)
        zip_stream = StringIO()
        zip_stream.write(file_data)
        zip_obj = zipfile.ZipFile(zip_stream,
                                  mode='r',
                                  compression=zipfile.ZIP_DEFLATED)
        if zipfile.is_zipfile(zip_stream):
            report_obj = self.pool.get('ir.actions.report')
            context['allformats'] = True
            mimetypes = dict(
                report_obj._get_in_mimetypes(cr, uid, context=context))
            styles_select = dict(report_obj._columns['styles_mode'].selection)
            if 'data.xml' in zip_obj.namelist():
                data = zip_obj.read('data.xml')
            else:
                raise osv.except_osv(_('Error!'),
                                     _('Aeroo report file is invalid!'))
            tree = lxml.etree.parse(StringIO(data))
            root = tree.getroot()
            info = ''
            report = root.xpath("//data/record[@model='ir.actions.report']")[0]
            style = root.xpath("//data/record[@model='report.stylesheets']")[0]
            rep_name = report.find("field[@name='name']").text
            rep_service = report.find("field[@name='report_name']").text
            rep_model = report.find("field[@name='model']").text
            rep_format = eval(
                report.find("field[@name='out_format']").attrib['search'],
                {})[0][2]
            rep_charset = report.find("field[@name='charset']").text
            parser_state = report.find("field[@name='parser_state']").text
            styles_mode = report.find("field[@name='styles_mode']").text
            tml_source = report.find("field[@name='tml_source']").text

            info += "Name: %s\n" % rep_name
            info += "Object: %s\n" % rep_model
            info += "Service Name: %s\n" % rep_service
            info += "Format: %s\n" % mimetypes.get(rep_format, 'oo-odt')
            info += "Template: %s\n" % (tml_source == 'parser'
                                        and 'defined by parser' or 'static')
            if rep_format == 'genshi-raw':
                info += "Charset: %s\n" % rep_charset
            info += "Parser: %s\n" % (parser_state == 'loc' and 'customized'
                                      or 'default')
            info += "Stylesheet: %s%s\n" % (
                styles_select[styles_mode].lower(), style is not None
                and " (%s)" % style.find("field[@name='name']").text)
            self.write(cr,
                       uid,
                       ids, {
                           'name': rep_service,
                           'info': info,
                           'state': 'info',
                           'file': base64.encodestring(data)
                       },
                       context=context)
        else:
            raise osv.except_osv(_('Error!'), _('Is not Aeroo report file.'))

        mod_obj = self.pool.get('ir.model.data')
        act_obj = self.pool.get('ir.actions.act_window')

        mod_id = mod_obj.search(
            cr, uid, [('name', '=', 'action_aeroo_report_import_wizard')])[0]
        res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id']
        act_win = act_obj.read(cr, uid, res_id, [])
        act_win['domain'] = [('id', 'in', ids)]
        act_win['context'] = {'default_ids': ids}
        return act_win

    _defaults = {
        'state': 'draft',
    }
class sale_purchase_journal_report(osv.osv_memory):
    _name = 'sale.purchase.journal.report'
    _description = 'Sale/Purchase Journal Report'

    def onchange_period_id(self, cr, uid, ids, period_id=False, context=None):
        res = {}
        if period_id:
            period = self.pool.get('account.period').browse(cr, uid, period_id, context=context)
            res['value'] = {'date_from': period.date_start, 'date_to': period.date_stop}
        return res
    
    
    _columns = {
        'company_id': fields.many2one('res.company', 'Company', required=True),
        'journal': fields.selection(
            [('purchase', 'Purchase'), ('sale', 'Sale')],
            'Journal type',
            select=True
        ),
        'periods': fields.many2one('account.period', 'Period', required=True),
        'date_from': fields.date("Start Date", required=True),
        'date_to': fields.date("End Date", required=True),        
    }

    def _get_period(self, cr, uid, context=None):
        if context is None:
            context = {}
        now = datetime.date.today()
        periods = self.pool.get('account.period').find(cr, uid, now + dateutil.relativedelta.relativedelta(months=-1))
        return periods and periods[0] or False

    _defaults = {
        "company_id": lambda obj, cr, uid, context: obj.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id,
        'journal': 'sale',
        'periods': _get_period,
    }

    def print_report(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        data = self.read(cr, uid, ids)[0]
        context['data'] = data
        context['landscape'] = True
        period = self.pool.get('account.period').browse(cr, uid, data['periods'][0], context=context)
        if data['date_from'] < period.date_start or data['date_from'] > period.date_stop or \
                data['date_to'] < period.date_start or data['date_to'] > period.date_stop:
            raise osv.except_osv(_('Error!'),_('Dates selected must be in the same period.'))
        if data['journal'] == 'sale':
            return self.pool['report'].get_action(cr, uid, [], 'l10n_ro_account_report.report_sale_journal', data=data, context=context)
        else:
            return self.pool['report'].get_action(cr, uid, [], 'l10n_ro_account_report.report_purchase_journal', data=data, context=context)

    def print_html_report(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        data = self.read(cr, uid, ids)[0]
        context['data'] = data
        context['landscape'] = True
        if data['journal'] == 'sale':
            return self.pool['report'].get_action(cr, uid, [], 'l10n_ro_account_report.report_sale_journal_html', data=data, context=context)
        else:
            return self.pool['report'].get_action(cr, uid, [], 'l10n_ro_account_report.report_purchase_journal_html', data=data, context=context)
class sos_common_report(osv.osv_memory):
    _name = "sos.common.report"
    _description = "SOS Common Report"

    def onchange_chart_id(self,
                          cr,
                          uid,
                          ids,
                          chart_account_id=False,
                          context=None):
        res = {}
        if chart_account_id:
            company_id = self.pool.get('account.account').browse(
                cr, uid, chart_account_id, context=context).company_id.id
            res['value'] = {'company_id': company_id}
        return res

    _columns = {
        'post_ids':
        fields.many2many(
            'sos.post',
            string='Filter on Posts',
            help=
            """Only selected Posts will be printed. Leave empty to print all Posts."""
        ),
        'project_ids':
        fields.many2many(
            'sos.project',
            string='Filter on Projects',
            help=
            """Only selected Projects will be printed. Leave empty to print all Projects."""
        ),
        'center_ids':
        fields.many2many(
            'sos.center',
            string='Filter on Centers',
            help=
            """Only selected Centers will be printed. Leave empty to print all Centers."""
        ),
        'filter':
        fields.selection([('filter_no', 'No Filters'), ('filter_date', 'Date'),
                          ('filter_period', 'Periods')],
                         "Filter by",
                         required=True),
        'date_from':
        fields.date("Start Date"),
        'date_to':
        fields.date("End Date"),
        'target_move':
        fields.selection([
            ('posted', 'All Posted Entries'),
            ('all', 'All Entries'),
        ], 'Target Moves'),
    }

    def pre_print_report(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}
        data['form'].update(
            self.read(cr, uid, ids, ['display_account'], context=context)[0])
        return data

    def onchange_filter(self, cr, uid, ids, filter='filter_no', context=None):
        res = {'value': {}}
        if filter == 'filter_no':
            res['value'] = {'date_from': False, 'date_to': False}
        if filter == 'filter_date':
            res['value'] = {
                'date_from': time.strftime('%Y-07-01'),
                'date_to': time.strftime('%Y-%m-%d')
            }
        return res

    def _get_account(self, cr, uid, context=None):
        user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
        accounts = self.pool.get('account.account').search(
            cr,
            uid, [('parent_id', '=', False),
                  ('company_id', '=', user.company_id.id)],
            limit=1)
        return accounts and accounts[0] or False

    def _get_all_journal(self, cr, uid, context=None):
        return self.pool.get('account.journal').search(cr, uid, [])

    _defaults = {
        'filter': 'filter_no',
        'target_move': 'posted',
    }

    def _build_contexts(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}
        result = {}

        if data['form']['filter'] == 'filter_date':
            result['date_from'] = data['form']['date_from']
            result['date_to'] = data['form']['date_to']
        return result

    def _print_report(self, cr, uid, ids, data, context=None):
        raise (_('Error!'), _('Not implemented.'))

    def check_report(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        data = {}
        data['ids'] = context.get('active_ids', [])
        data['model'] = context.get('active_model', 'ir.ui.menu')
        data['form'] = self.read(
            cr,
            uid,
            ids, ['date_from', 'date_to', 'filter', 'target_move'],
            context=context)[0]

        used_context = self._build_contexts(cr,
                                            uid,
                                            ids,
                                            data,
                                            context=context)
        data['form']['used_context'] = used_context
        return self._print_report(cr, uid, ids, data, context=context)