コード例 #1
0
class resource_resource(osv.osv):
    _name = "resource.resource"
    _description = "Resource Detail"
    _columns = {
        'name': fields.char("Name", required=True),
        'code': fields.char('Code', size=16, copy=False),
        'active' : fields.boolean('Active', track_visibility='onchange',
            help="If the active field is set to False, it will allow you to hide the resource record without removing it."),
        'company_id' : fields.many2one('res.company', 'Company'),
        'resource_type': fields.selection([('user','Human'),('material','Material')], 'Resource Type', required=True),
        'user_id' : fields.many2one('res.users', 'User', help='Related user name for the resource to manage its access.'),
        'time_efficiency' : fields.float('Efficiency Factor', size=8, required=True, help="This field depict the efficiency of the resource to complete tasks. e.g  resource put alone on a phase of 5 days with 5 tasks assigned to him, will show a load of 100% for this phase by default, but if we put a efficiency of 200%, then his load will only be 50%."),
        'calendar_id' : fields.many2one("resource.calendar", "Working Time", help="Define the schedule of resource"),
    }

    _defaults = {
        'resource_type' : 'user',
        'time_efficiency' : 1,
        'active' : True,
        'company_id': lambda self, cr, uid, context: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.resource', context=context)
    }

    def copy(self, cr, uid, id, default=None, context=None):
        if default is None:
            default = {}
        if not default.get('name', False):
            default.update(name=_('%s (copy)') % (self.browse(cr, uid, id, context=context).name))
        return super(resource_resource, self).copy(cr, uid, id, default, context)
コード例 #2
0
ファイル: stock_account.py プロジェクト: yuancloud/yuancloud
class stock_location(osv.osv):
    _inherit = "stock.location"

    _columns = {
        'valuation_in_account_id':
        fields.many2one(
            'account.account',
            'Stock Valuation Account (Incoming)',
            domain=[('internal_type', '=', 'other'),
                    ('deprecated', '=', False)],
            help=
            "Used for real-time inventory valuation. When set on a virtual location (non internal type), "
            "this account will be used to hold the value of products being moved from an internal location "
            "into this location, instead of the generic Stock Output Account set on the product. "
            "This has no effect for internal locations."),
        'valuation_out_account_id':
        fields.many2one(
            'account.account',
            'Stock Valuation Account (Outgoing)',
            domain=[('internal_type', '=', 'other'),
                    ('deprecated', '=', False)],
            help=
            "Used for real-time inventory valuation. When set on a virtual location (non internal type), "
            "this account will be used to hold the value of products being moved out of this location "
            "and into an internal location, instead of the generic Stock Output Account set on the product. "
            "This has no effect for internal locations."),
    }
コード例 #3
0
class resource_calendar_leaves(osv.osv):
    _name = "resource.calendar.leaves"
    _description = "Leave Detail"
    _columns = {
        'name' : fields.char("Name"),
        'company_id' : fields.related('calendar_id','company_id',type='many2one',relation='res.company',string="Company", store=True, readonly=True),
        'calendar_id' : fields.many2one("resource.calendar", "Working Time"),
        'date_from' : fields.datetime('Start Date', required=True),
        'date_to' : fields.datetime('End Date', required=True),
        'resource_id' : fields.many2one("resource.resource", "Resource", help="If empty, this is a generic holiday for the company. If a resource is set, the holiday/leave is only for this resource"),
    }

    def check_dates(self, cr, uid, ids, context=None):
        for leave in self.browse(cr, uid, ids, context=context):
            if leave.date_from and leave.date_to and leave.date_from > leave.date_to:
                return False
        return True

    _constraints = [
        (check_dates, 'Error! leave start-date must be lower then leave end-date.', ['date_from', 'date_to'])
    ]

    def onchange_resource(self, cr, uid, ids, resource, context=None):
        result = {}
        if resource:
            resource_pool = self.pool.get('resource.resource')
            result['calendar_id'] = resource_pool.browse(cr, uid, resource, context=context).calendar_id.id
            return {'value': result}
        return {'value': {'calendar_id': []}}
コード例 #4
0
class PaymentMethod(osv.Model):
    _name = 'payment.method'
    _order = 'partner_id'

    _columns = {
        'name': fields.char('Name', help='Name of the payment method'),
        'partner_id': fields.many2one('res.partner', 'Partner', required=True),
        'acquirer_id': fields.many2one('payment.acquirer', 'Acquirer Account', required=True),
        'acquirer_ref': fields.char('Acquirer Ref.', required=True),
        'active': fields.boolean('Active'),
        'payment_ids': fields.one2many('payment.transaction', 'payment_method_id', 'Payment Transactions'),
    }

    _defaults = {
        'active': True
    }

    def create(self, cr, uid, values, context=None):
        # call custom create method if defined (i.e. ogone_create for ogone)
        if values.get('acquirer_id'):
            acquirer = self.pool['payment.acquirer'].browse(cr, uid, values.get('acquirer_id'), context=context)

            # custom create
            custom_method_name = '%s_create' % acquirer.provider
            if hasattr(self, custom_method_name):
                values.update(getattr(self, custom_method_name)(cr, uid, values, context=context))

        return super(PaymentMethod, self).create(cr, uid, values, context=context)
コード例 #5
0
class Post(osv.Model):
    _inherit = 'forum.post'

    _columns = {
        'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC', ondelete='set null'),
        'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage'),
        'color': fields.integer('Color Index')
    }

    def _get_default_stage_id(self, cr, uid, context=None):
        stage_ids = self.pool["forum.documentation.stage"].search(cr, uid, [], limit=1, context=context)
        return stage_ids and stage_ids[0] or False

    _defaults = {
        'documentation_stage_id': _get_default_stage_id,
    }

    def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
        stage_obj = self.pool.get('forum.documentation.stage')
        stage_ids = stage_obj.search(cr, uid, [], context=context)
        result = stage_obj.name_get(cr, uid, stage_ids, context=context)
        return result, {}

    _group_by_full = {
        'documentation_stage_id': _read_group_stage_ids,
    }
コード例 #6
0
class report_transaction_pos(osv.osv):
    _name = "report.transaction.pos"
    _description = "transaction for the pos"
    _auto = False
    _columns = {
        'date_create':
        fields.char('Date', size=16, readonly=True),
        'journal_id':
        fields.many2one('account.journal', 'Sales Journal', readonly=True),
        'jl_id':
        fields.many2one('account.journal', 'Cash Journals', readonly=True),
        'user_id':
        fields.many2one('res.users', 'User', readonly=True),
        'no_trans':
        fields.float('Number of Transaction', readonly=True),
        'amount':
        fields.float('Amount', readonly=True),
        'invoice_id':
        fields.float('Nbr Invoice', readonly=True),
        'invoice_am':
        fields.float('Invoice Amount', readonly=True),
        'product_nb':
        fields.float('Product Nb.', readonly=True),
        'disc':
        fields.float('Disc.', readonly=True),
    }

    def init(self, cr):
        tools.drop_view_if_exists(cr, 'report_transaction_pos')
        cr.execute("""
            create or replace view report_transaction_pos as (
               select
                    min(absl.id) as id,
                    count(absl.id) as no_trans,
                    sum(absl.amount) as amount,
                    sum((100.0-line.discount) * line.price_unit * line.qty / 100.0) as disc,
                    to_char(date_trunc('day',absl.create_date),'YYYY-MM-DD')::text as date_create,
                    po.user_id as user_id,
                    po.sale_journal as journal_id,
                    abs.journal_id as jl_id,
                    count(po.invoice_id) as invoice_id,
                    count(p.id) as product_nb
                from
                    account_bank_statement_line as absl,
                    account_bank_statement as abs,
                    product_product as p,
                    pos_order_line as line,
                    pos_order as po
                where
                    absl.pos_statement_id = po.id and
                    line.order_id=po.id and
                    line.product_id=p.id and
                    absl.statement_id=abs.id

                group by
                    po.user_id,po.sale_journal, abs.journal_id,
                    to_char(date_trunc('day',absl.create_date),'YYYY-MM-DD')::text
                )
        """)
コード例 #7
0
class oauth_provider_entity_extend(osv.Model):
    _name = 'oauth_provider_entity_extend'
    _columns = {
        'res_user_id':fields.many2one('res.users','user_id'),
        'oauth_provider_id': fields.many2one('auth.oauth.provider', 'OAuth Provider'),
        'oauth_uid': fields.char('OAuth User ID', help="Oauth Provider user_id", copy=False),
        'oauth_access_token': fields.char('OAuth Access Token', readonly=True, copy=False),
    }
コード例 #8
0
ファイル: stock_move.py プロジェクト: yuancloud/yuancloud
class stock_move_consume(osv.osv_memory):
    _name = "stock.move.consume"
    _description = "Consume Products"

    _columns = {
        'product_id': fields.many2one('product.product', 'Product', required=True, select=True),
        'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
        'product_uom': fields.many2one('product.uom', 'Product Unit of Measure', required=True),
        'location_id': fields.many2one('stock.location', 'Location', required=True),
        'restrict_lot_id': fields.many2one('stock.production.lot', 'Lot'),
    }

    #TOFIX: product_uom should not have different category of default UOM of product. Qty should be convert into UOM of original move line before going in consume and scrap
    def default_get(self, cr, uid, fields, context=None):
        if context is None:
            context = {}
        res = super(stock_move_consume, self).default_get(cr, uid, fields, context=context)
        move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
        if 'product_id' in fields:
            res.update({'product_id': move.product_id.id})
        if 'product_uom' in fields:
            res.update({'product_uom': move.product_uom.id})
        if 'product_qty' in fields:
            res.update({'product_qty': move.product_uom_qty})
        if 'location_id' in fields:
            res.update({'location_id': move.location_id.id})
        return res



    def do_move_consume(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        move_obj = self.pool.get('stock.move')
        uom_obj = self.pool.get('product.uom')
        production_obj = self.pool.get('mrp.production')
        move_ids = context['active_ids']
        move = move_obj.browse(cr, uid, move_ids[0], context=context)
        production_id = move.raw_material_production_id.id
        production = production_obj.browse(cr, uid, production_id, context=context)
        precision = self.pool['decimal.precision'].precision_get(cr, uid, 'Product Unit of Measure')

        for data in self.browse(cr, uid, ids, context=context):
            qty = uom_obj._compute_qty(cr, uid, data['product_uom'].id, data.product_qty, data.product_id.uom_id.id)
            remaining_qty = move.product_qty - qty
            #check for product quantity is less than previously planned
            if float_compare(remaining_qty, 0, precision_digits=precision) >= 0:
                move_obj.action_consume(cr, uid, move_ids, qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id, context=context)
            else:
                consumed_qty = min(move.product_qty, qty)
                new_moves = move_obj.action_consume(cr, uid, move_ids, consumed_qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id, context=context)
                #consumed more in wizard than previously planned
                extra_more_qty = qty - consumed_qty
                #create new line for a remaining qty of the product
                extra_move_id = production_obj._make_consume_line_from_data(cr, uid, production, data.product_id, data.product_id.uom_id.id, extra_more_qty, context=context)
                move_obj.write(cr, uid, [extra_move_id], {'restrict_lot_id': data.restrict_lot_id.id}, context=context)
                move_obj.action_done(cr, uid, [extra_move_id], context=context)
        return {'type': 'ir.actions.act_window_close'}
コード例 #9
0
ファイル: stock.py プロジェクト: yuancloud/yuancloud
class stock_warehouse_orderpoint(osv.osv):
    _inherit = "stock.warehouse.orderpoint"

    _columns = {
        'calendar_id': fields.many2one('resource.calendar', 'Calendar',
                                       help="In the calendar you can define the days that the goods will be delivered.  That way the scheduler will only take into account the goods needed until the second delivery and put the procurement date as the first delivery.  "),
        'purchase_calendar_id': fields.many2one('resource.calendar', 'Purchase Calendar'),
        'last_execution_date': fields.datetime('Last Execution Date', readonly=True),
    }
コード例 #10
0
ファイル: sales_team.py プロジェクト: yuancloud/yuancloud
class crm_team(osv.Model):
    _name = "crm.team"
    _inherit = ['mail.thread', 'ir.needaction_mixin']
    _description = "Sales Team"
    _order = "name"
    _period_number = 5

    def _get_default_team_id(self, cr, uid, context=None, user_id=None):
        if context is None:
            context = {}
        if user_id is None:
            user_id = uid
        team_id = context.get('default_team_id')
        if not team_id:
            team_ids = self.search(cr,
                                   uid, [
                                       '|', ('user_id', '=', user_id),
                                       ('member_ids', 'in', user_id)
                                   ],
                                   limit=1,
                                   context=context)
            team_id = team_ids[0] if team_ids else False
        if not team_id:
            team_id = self.pool['ir.model.data'].xmlid_to_res_id(
                cr, uid, 'sales_team.team_sales_department')
        return team_id

    _columns = {
        'name': fields.char('Sales Team', size=64, required=True, translate=True),
        'code': fields.char('Code', size=8),
        'active': fields.boolean('Active', help="If the active field is set to "\
                        "false, it will allow you to hide the sales team without removing it."),
        'company_id': fields.many2one('res.company', 'Company'),
        'user_id': fields.many2one('res.users', 'Team Leader'),
        'member_ids': fields.one2many('res.users', 'sale_team_id', 'Team Members'),
        'reply_to': fields.char('Reply-To', size=64, help="The email address put in the 'Reply-To' of all emails sent by YuanCloud about cases in this sales team"),
        'working_hours': fields.float('Working Hours', digits=(16, 2)),
        'color': fields.integer('Color Index'),
    }

    _defaults = {
        'active':
        1,
        'company_id':
        lambda self, cr, uid, context: self.pool.get('res.company').
        _company_default_get(cr, uid, 'crm.team', context=context),
    }

    _sql_constraints = [('code_uniq', 'unique (code)',
                         'The code of the sales team must be unique !')]

    def create(self, cr, uid, values, context=None):
        if context is None:
            context = {}
        context['mail_create_nosubscribe'] = True
        return super(crm_team, self).create(cr, uid, values, context=context)
コード例 #11
0
class hr_contract(osv.osv):

    _inherit = 'hr.contract'
    _description = 'Employee Contract'
    _columns = {
        'analytic_account_id':
        fields.many2one('account.analytic.account', 'Analytic Account'),
        'journal_id':
        fields.many2one('account.journal', 'Salary Journal'),
    }
コード例 #12
0
class stock_landed_cost_lines(osv.osv):
    _name = 'stock.landed.cost.lines'
    _description = 'Stock Landed Cost Lines'

    def onchange_product_id(self,
                            cr,
                            uid,
                            ids,
                            product_id=False,
                            context=None):
        result = {}
        if not product_id:
            return {'value': {'quantity': 0.0, 'price_unit': 0.0}}

        product = self.pool.get('product.product').browse(cr,
                                                          uid,
                                                          product_id,
                                                          context=context)
        result['name'] = product.name
        result['split_method'] = product.split_method
        result['price_unit'] = product.standard_price
        result[
            'account_id'] = product.property_account_expense_id and product.property_account_expense_id.id or product.categ_id.property_account_expense_categ_id.id
        return {'value': result}

    _columns = {
        'name':
        fields.char('Description'),
        'cost_id':
        fields.many2one('stock.landed.cost',
                        'Landed Cost',
                        required=True,
                        ondelete='cascade'),
        'product_id':
        fields.many2one('product.product', 'Product', required=True),
        'price_unit':
        fields.float('Cost',
                     required=True,
                     digits_compute=dp.get_precision('Product Price')),
        'split_method':
        fields.selection(product.SPLIT_METHOD,
                         string='Split Method',
                         required=True),
        'account_id':
        fields.many2one('account.account',
                        'Account',
                        domain=[('internal_type', '!=', 'view'),
                                ('internal_type', '!=', 'closed'),
                                ('deprecated', '=', False)]),
    }
コード例 #13
0
class procurement_rule(osv.osv):
    '''
    A rule describe what a procurement should do; produce, buy, move, ...
    '''
    _name = 'procurement.rule'
    _description = "Procurement Rule"
    _order = "name"

    def _get_action(self, cr, uid, context=None):
        return []

    _columns = {
        'name':
        fields.char(
            'Name',
            required=True,
            translate=True,
            help=
            "This field will fill the packing origin and the name of its moves"
        ),
        'active':
        fields.boolean(
            'Active',
            help=
            "If unchecked, it will allow you to hide the rule without removing it."
        ),
        'group_propagation_option':
        fields.selection([('none', 'Leave Empty'), ('propagate', 'Propagate'),
                          ('fixed', 'Fixed')],
                         string="Propagation of Procurement Group"),
        'group_id':
        fields.many2one('procurement.group', 'Fixed Procurement Group'),
        'action':
        fields.selection(selection=lambda s, cr, uid, context=None: s.
                         _get_action(cr, uid, context=context),
                         string='Action',
                         required=True),
        'sequence':
        fields.integer('Sequence'),
        'company_id':
        fields.many2one('res.company', 'Company'),
    }

    _defaults = {
        'group_propagation_option': 'propagate',
        'sequence': 20,
        'active': True,
    }
コード例 #14
0
class report_sales_by_user_pos(osv.osv):
    _name = "report.sales.by.user.pos"
    _description = "Sales by user"
    _auto = False
    _columns = {
        'date_order':
        fields.date('Order Date', required=True, select=True),
        'amount':
        fields.float('Total', readonly=True, select=True),
        'qty':
        fields.float('Quantity', readonly=True, select=True),
        'user_id':
        fields.many2one('res.users', 'User', readonly=True, select=True),
    }

    def init(self, cr):
        tools.drop_view_if_exists(cr, 'report_sales_by_user_pos')
        cr.execute("""
            create or replace view report_sales_by_user_pos as (
                select
                    min(po.id) as id,
                    to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text as date_order,
                    po.user_id as user_id,
                    sum(pol.qty)as qty,
                    sum((pol.price_unit * pol.qty * (1 - (pol.discount) / 100.0))) as amount
                from
                    pos_order as po,pos_order_line as pol,product_product as pp,product_template as pt
                where
                    pt.id=pp.product_tmpl_id and pp.id=pol.product_id and po.id = pol.order_id
               group by
                    to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text,
                    po.user_id

                )
        """)
コード例 #15
0
class ir_actions_report(osv.Model):
    _inherit = 'ir.actions.report.xml'

    def associated_view(self, cr, uid, ids, context):
        """Used in the ir.actions.report.xml form view in order to search naively after the view(s)
        used in the rendering.
        """
        try:
            report_name = self.browse(cr, uid, ids[0], context).report_name
            act_window_obj = self.pool.get('ir.actions.act_window')
            view_action = act_window_obj.for_xml_id(cr,
                                                    uid,
                                                    'base',
                                                    'action_ui_view',
                                                    context=context)
            view_action['domain'] = [('name', 'ilike',
                                      report_name.split('.')[1]),
                                     ('type', '=', 'qweb')]
            return view_action
        except:
            return False

    _columns = {
        'paperformat_id': fields.many2one('report.paperformat', 'Paper format')
    }
コード例 #16
0
class mrp_product_produce_line(osv.osv_memory):
    _name = "mrp.product.produce.line"
    _description = "Product Produce Consume lines"

    _columns = {
        'product_id':
        fields.many2one('product.product', string='Product'),
        'product_qty':
        fields.float(
            'Quantity (in default UoM)',
            digits_compute=dp.get_precision('Product Unit of Measure')),
        'lot_id':
        fields.many2one('stock.production.lot', string='Lot'),
        'produce_id':
        fields.many2one('mrp.product.produce', string="Produce"),
    }
コード例 #17
0
ファイル: res_users.py プロジェクト: yuancloud/yuancloud
class res_users(osv.osv):
    _inherit = 'res.users'
    _columns = {
        'pos_security_pin':
        fields.char(
            'Security PIN',
            size=32,
            help=
            'A Security PIN used to protect sensible functionality in the Point of Sale'
        ),
        'pos_config':
        fields.many2one('pos.config',
                        'Default Point of Sale',
                        domain=[('state', '=', 'active')]),
    }

    def _check_pin(self, cr, uid, ids, context=None):
        for user in self.browse(cr, uid, ids, context=context):
            if user.pos_security_pin and not user.pos_security_pin.isdigit():
                return False
        return True

    _constraints = [
        (_check_pin, "Security PIN can only contain digits",
         ['pos_security_pin']),
    ]
コード例 #18
0
ファイル: stock.py プロジェクト: yuancloud/yuancloud
class stock_move(osv.osv):
    _inherit = 'stock.move'
    _columns = {
        'purchase_line_id':
        fields.many2one('purchase.order.line',
                        'Purchase Order Line',
                        ondelete='set null',
                        select=True,
                        readonly=True),
    }

    def get_price_unit(self, cr, uid, move, context=None):
        """ Returns the unit price to store on the quant """
        if move.purchase_line_id:
            return move.price_unit
        return super(stock_move, self).get_price_unit(cr,
                                                      uid,
                                                      move,
                                                      context=context)

    def copy(self, cr, uid, id, default=None, context=None):
        default = default or {}
        context = context or {}
        if not default.get('split_from'):
            #we don't want to propagate the link to the purchase order line except in case of move split
            default['purchase_line_id'] = False
        return super(stock_move, self).copy(cr, uid, id, default, context)
コード例 #19
0
ファイル: sales_team.py プロジェクト: yuancloud/yuancloud
class res_partner(osv.Model):
    _inherit = 'res.partner'
    _columns = {
        'team_id': fields.many2one('crm.team',
                                   'Sales Team',
                                   oldname='section_id'),
    }
コード例 #20
0
class res_partner(osv.osv):
    
    _name = 'res.partner'
    _inherit = 'res.partner'
    _columns = {
        'state_id': fields.many2one("res.country.state", 'Ubication', domain="[('country_id','=',country_id),('type','=','normal')]"),
        }
コード例 #21
0
class One2ManyChild(orm.Model):
    _name = 'export.one2many.child'
    # FIXME: orm.py:1161, fix to name_get on m2o field
    _rec_name = 'value'

    _columns = {
        'parent_id': fields.many2one('export.one2many'),
        'str': fields.char('unknown', size=None),
        'value': fields.integer(),
    }

    def name_get(self, cr, uid, ids, context=None):
        return [(record.id, "%s:%s" % (self._name, record.value))
                for record in self.browse(cr, uid, ids, context=context)]

    def name_search(self,
                    cr,
                    user,
                    name='',
                    args=None,
                    operator='ilike',
                    context=None,
                    limit=100):
        if isinstance(name, basestring) and name.split(':')[0] == self._name:
            ids = self.search(cr, user,
                              [['value', operator,
                                int(name.split(':')[1])]])
            return self.name_get(cr, user, ids, context=context)
        else:
            return []
コード例 #22
0
class mail_mail(osv.osv):
    _inherit = "mail.mail"
    _columns = {
        'fetchmail_server_id':
        fields.many2one('fetchmail.server',
                        "Inbound Mail Server",
                        readonly=True,
                        select=True,
                        oldname='server_id'),
    }

    def create(self, cr, uid, values, context=None):
        if context is None:
            context = {}
        fetchmail_server_id = context.get('fetchmail_server_id')
        if fetchmail_server_id:
            values['fetchmail_server_id'] = fetchmail_server_id
        res = super(mail_mail, self).create(cr, uid, values, context=context)
        return res

    def write(self, cr, uid, ids, values, context=None):
        if context is None:
            context = {}
        fetchmail_server_id = context.get('fetchmail_server_id')
        if fetchmail_server_id:
            values['fetchmail_server_id'] = fetchmail_server_id
        res = super(mail_mail, self).write(cr,
                                           uid,
                                           ids,
                                           values,
                                           context=context)
        return res
コード例 #23
0
class res_company(osv.Model):
    _inherit = 'res.company'

    _columns = {
        'paperformat_id': fields.many2one('report.paperformat', 'Paper format')
    }

    def init(self, cr):
        # set a default paperformat based on rml one.
        ref = partial(self.pool['ir.model.data'].xmlid_to_res_id, cr,
                      SUPERUSER_ID)

        ids = self.search(cr, SUPERUSER_ID, [('paperformat_id', '=', False)])
        for company in self.browse(cr, SUPERUSER_ID, ids):
            paperformat_id = {
                'a4': ref('report.paperformat_euro'),
                'us_letter': ref('report.paperformat_us'),
            }.get(company.rml_paper_format) or ref('report.paperformat_euro')

            if paperformat_id:
                company.write({'paperformat_id': paperformat_id})

        sup = super(res_company, self)
        if hasattr(sup, 'init'):
            sup.init(cr)
コード例 #24
0
ファイル: mrp_report.py プロジェクト: yuancloud/yuancloud
class report_workcenter_load(osv.osv):
    _name = "report.workcenter.load"
    _description = "Work Center Load"
    _auto = False
    _log_access = False
    _columns = {
        'name':
        fields.char('Week', required=True),
        'workcenter_id':
        fields.many2one('mrp.workcenter', 'Work Center', required=True),
        'cycle':
        fields.float('Number of Cycles'),
        'hour':
        fields.float('Number of Hours'),
    }

    def init(self, cr):
        cr.execute("""
            create or replace view report_workcenter_load as (
                SELECT
                    min(wl.id) as id,
                    to_char(p.date_planned,'YYYY:mm:dd') as name,
                    SUM(wl.hour) AS hour,
                    SUM(wl.cycle) AS cycle,
                    wl.workcenter_id as workcenter_id
                FROM
                    mrp_production_workcenter_line wl
                    LEFT JOIN mrp_production p
                        ON p.id = wl.production_id
                GROUP BY
                    wl.workcenter_id,
                    to_char(p.date_planned,'YYYY:mm:dd')
            )""")
コード例 #25
0
class hr_holidays_remaining_leaves_user(osv.osv):
    _name = "hr.holidays.remaining.leaves.user"
    _description = "Total holidays by type"
    _auto = False
    _columns = {
        'name': fields.char('Employee'),
        'no_of_leaves': fields.integer('Remaining leaves'),
        'user_id': fields.many2one('res.users', 'User'),
        'leave_type': fields.char('Leave Type'),
    }

    def init(self, cr):
        tools.drop_view_if_exists(cr, 'hr_holidays_remaining_leaves_user')
        cr.execute("""
            CREATE or REPLACE view hr_holidays_remaining_leaves_user as (
                 SELECT
                    min(hrs.id) as id,
                    rr.name as name,
                    sum(hrs.number_of_days) as no_of_leaves,
                    rr.user_id as user_id,
                    hhs.name as leave_type
                FROM
                    hr_holidays as hrs, hr_employee as hre,
                    resource_resource as rr,hr_holidays_status as hhs
                WHERE
                    hrs.employee_id = hre.id and
                    hre.resource_id =  rr.id and
                    hhs.id = hrs.holiday_status_id
                GROUP BY
                    rr.name,rr.user_id,hhs.name
            )
        """)
コード例 #26
0
class hr_salary_rule(osv.osv):
    _inherit = 'hr.salary.rule'
    _columns = {
        'analytic_account_id':
        fields.many2one('account.analytic.account', 'Analytic Account'),
        'account_tax_id':
        fields.many2one('account.tax', 'Tax'),
        'account_debit':
        fields.many2one('account.account',
                        'Debit Account',
                        domain=[('deprecated', '=', False)]),
        'account_credit':
        fields.many2one('account.account',
                        'Credit Account',
                        domain=[('deprecated', '=', False)]),
    }
コード例 #27
0
class pay_sale_order(orm.TransientModel):
    _name = 'pay.sale.order'
    _description = 'Wizard to generate a payment from the sale order'

    _columns = {
        'journal_id': fields.many2one('account.journal', 'Journal'),
        'amount': fields.float('Amount',
                               digits_compute=dp.get_precision('Sale Price')),
        'date': fields.datetime('Payment Date'),
        'description': fields.char('Description', size=64),
    }

    def _get_journal_id(self, cr, uid, context=None):
        if context is None:
            context = {}
        if context.get('active_id'):
            sale_obj = self.pool.get('sale.order')
            order = sale_obj.browse(cr, uid, context['active_id'],
                                    context=context)
            if order.payment_method_id:
                return order.payment_method_id.journal_id.id
        return False

    def _get_amount(self, cr, uid, context=None):
        if context is None:
            context = {}
        if context.get('active_id'):
            sale_obj = self.pool.get('sale.order')
            order = sale_obj.browse(cr, uid, context['active_id'],
                                    context=context)
            return order.residual
        return False

    _defaults = {
        'journal_id': _get_journal_id,
        'amount': _get_amount,
        'date': fields.datetime.now,
    }

    def pay_sale_order(self, cr, uid, ids, context=None):
        """ Pay the sale order """
        wizard = self.browse(cr, uid, ids[0], context=context)
        sale_obj = self.pool.get('sale.order')
        sale_obj.add_payment(cr, uid,
                             context['active_id'],
                             wizard.journal_id.id,
                             wizard.amount,
                             wizard.date,
                             description=wizard.description,
                             context=context)
        return {'type': 'ir.actions.act_window_close'}

    def pay_sale_order_and_confirm(self, cr, uid, ids, context=None):
        """ Pay the sale order """
        self.pay_sale_order(cr, uid, ids, context=context)
        sale_obj = self.pool.get('sale.order')
        return sale_obj.action_button_confirm(cr, uid,
                                              [context['active_id']],
                                              context=context)
コード例 #28
0
ファイル: utm.py プロジェクト: yuancloud/yuancloud
class utm_mixin(osv.AbstractModel):
    """Mixin class for objects which can be tracked by marketing. """
    _name = 'utm.mixin'

    _columns = {
        'campaign_id': fields.many2one('utm.campaign', 'Campaign',  # old domain ="['|',('team_id','=',team_id),('team_id','=',False)]"
                                       help="This is a name that helps you keep track of your different campaign efforts Ex: Fall_Drive, Christmas_Special"),
        'source_id': fields.many2one('utm.source', 'Source', help="This is the source of the link Ex: Search Engine, another domain, or name of email list"),
        'medium_id': fields.many2one('utm.medium', 'Medium', help="This is the method of delivery. Ex: Postcard, Email, or Banner Ad", oldname='channel_id'),
    }

    def tracking_fields(self):
        return [
            # ("URL_PARAMETER", "FIELD_NAME_MIXIN", "NAME_IN_COOKIES")
            ('utm_campaign', 'campaign_id', 'yuancloud_utm_campaign'),
            ('utm_source', 'source_id', 'yuancloud_utm_source'),
            ('utm_medium', 'medium_id', 'yuancloud_utm_medium')
        ]

    def tracking_get_values(self, cr, uid, vals, context=None):
        for key, fname, cook in self.tracking_fields():
            field = self._fields[fname]
            value = vals.get(fname) or (request and request.httprequest.cookies.get(cook))  # params.get should be always in session by the dispatch from ir_http
            if field.type == 'many2one' and isinstance(value, basestring):
                # if we receive a string for a many2one, we search/create the id
                if value:
                    Model = self.pool[field.comodel_name]
                    rel_id = Model.name_search(cr, uid, value, context=context)
                    if rel_id:
                        rel_id = rel_id[0][0]
                    else:
                        rel_id = Model.create(cr, uid, {'name': value}, context=context)
                vals[fname] = rel_id
            else:
                # Here the code for others cases that many2one
                vals[fname] = value
        return vals

    def _get_default_track(self, cr, uid, field, context=None):
        return self.tracking_get_values(cr, uid, {}, context=context).get(field)

    _defaults = {
        'source_id': lambda self, cr, uid, ctx: self._get_default_track(cr, uid, 'source_id', ctx),
        'campaign_id': lambda self, cr, uid, ctx: self._get_default_track(cr, uid, 'campaign_id', ctx),
        'medium_id': lambda self, cr, uid, ctx: self._get_default_track(cr, uid, 'medium_id', ctx),
    }
コード例 #29
0
class gamification_badge_user(osv.Model):
    """User having received a badge"""

    _name = 'gamification.badge.user'
    _description = 'Gamification user badge'
    _order = "create_date desc"
    _rec_name = "badge_name"

    _columns = {
        'user_id': fields.many2one('res.users', string="User", required=True, ondelete="cascade"),
        'sender_id': fields.many2one('res.users', string="Sender", help="The user who has send the badge"),
        'badge_id': fields.many2one('gamification.badge', string='Badge', required=True, ondelete="cascade"),
        'challenge_id': fields.many2one('gamification.challenge', string='Challenge originating', help="If this badge was rewarded through a challenge"),
        'comment': fields.text('Comment'),
        'badge_name': fields.related('badge_id', 'name', type="char", string="Badge Name"),
        'create_date': fields.datetime('Created', readonly=True),
        'create_uid': fields.many2one('res.users', string='Creator', readonly=True),
    }


    def _send_badge(self, cr, uid, ids, context=None):
        """Send a notification to a user for receiving a badge

        Does not verify constrains on badge granting.
        The users are added to the owner_ids (create badge_user if needed)
        The stats counters are incremented
        :param ids: list(int) of badge users that will receive the badge
        """
        res = True
        temp_obj = self.pool.get('mail.template')
        user_obj = self.pool.get('res.users')
        template_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'gamification', 'email_template_badge_received')[1]
        for badge_user in self.browse(cr, uid, ids, context=context):
            template = temp_obj.get_email_template(cr, uid, template_id, badge_user.id, context=context)
            body_html = temp_obj.render_template(cr, uid, template.body_html, 'gamification.badge.user', badge_user.id, context=template._context)
            res = user_obj.message_post(
                cr, uid, badge_user.user_id.id,
                body=body_html,
                subtype='gamification.mt_badge_granted',
                partner_ids=[badge_user.user_id.partner_id.id],
                context=context)
        return res

    def create(self, cr, uid, vals, context=None):
        self.pool.get('gamification.badge').check_granting(cr, uid, badge_id=vals.get('badge_id'), context=context)
        return super(gamification_badge_user, self).create(cr, uid, vals, context=context)
コード例 #30
0
class stock_return_picking_line(osv.osv_memory):
    _name = "stock.return.picking.line"
    _rec_name = 'product_id'

    _columns = {
        'product_id':
        fields.many2one('product.product', string="Product", required=True),
        'quantity':
        fields.float(
            "Quantity",
            digits_compute=dp.get_precision('Product Unit of Measure'),
            required=True),
        'wizard_id':
        fields.many2one('stock.return.picking', string="Wizard"),
        'move_id':
        fields.many2one('stock.move', "Move"),
    }