コード例 #1
0
ファイル: partner.py プロジェクト: ecoreos/hz
class res_partner(osv.osv):
    _inherit = 'res.partner'
    _columns = {
        'property_stock_customer':
        fields.property(
            type='many2one',
            relation='stock.location',
            string="Customer Location",
            help=
            "This stock location will be used, instead of the default one, as the destination location for goods you send to this partner"
        ),
        'property_stock_supplier':
        fields.property(
            type='many2one',
            relation='stock.location',
            string="Vendor Location",
            help=
            "This stock location will be used, instead of the default one, as the source location for goods you receive from the current partner"
        ),
    }
コード例 #2
0
ファイル: partner.py プロジェクト: LiberTang0/5
class res_partner(osv.osv):
    _name = 'res.partner'
    _inherit = 'res.partner'
    _columns = {
        'property_product_pricelist': fields.property(
            type='many2one', 
            relation='product.pricelist', 
            string="Sale Pricelist", 
            help="This pricelist will be used, instead of the default one, for sales to the current partner"),
    }

    def _commercial_fields(self, cr, uid, context=None):
        return super(res_partner, self)._commercial_fields(cr, uid, context=context) + ['property_product_pricelist']
コード例 #3
0
ファイル: test_related.py プロジェクト: genuineaffairs/ecore5
    def test_1_property_multicompany(self):
        cr, uid = self.cr, self.uid

        parent_company_id = self.imd.get_object_reference(cr, uid, 'base', 'main_company')[1]
        country_be = self.imd.get_object_reference(cr, uid, 'base', 'be')[1]
        country_fr = self.imd.get_object_reference(cr, uid, 'base', 'fr')[1]
        group_partner_manager = self.imd.get_object_reference(cr, uid, 'base', 'group_partner_manager')[1]
        group_multi_company = self.imd.get_object_reference(cr, uid, 'base', 'group_multi_company')[1]

        sub_company = self.company.create(cr, uid, {'name': 'MegaCorp', 'parent_id': parent_company_id})
        alice = self.user.create(cr, uid, {'name': 'Alice',
            'login':'******',
            'email':'*****@*****.**',
            'company_id':parent_company_id,
            'company_ids':[(6, 0, [parent_company_id, sub_company])],
            'country_id':country_be,
            'groups_id': [(6, 0, [group_partner_manager, group_multi_company])]
        })
        bob = self.user.create(cr, uid, {'name': 'Bob',
            'login':'******',
            'email':'*****@*****.**',
            'company_id':sub_company,
            'company_ids':[(6, 0, [parent_company_id, sub_company])],
            'country_id':country_fr,
            'groups_id': [(6, 0, [group_partner_manager, group_multi_company])]
        })
        
        self.partner._columns = dict(self.partner._columns)
        self.partner._columns.update({
            'property_country': fields.property(type='many2one', relation="res.country", string="Country by company"),
        })
        self.partner._field_create(cr)

        partner_id = self.partner.create(cr, alice, {
            'name': 'An International Partner',
            'email': '*****@*****.**',
            'company_id': parent_company_id,
        })
        self.partner.write(cr, bob, [partner_id], {'property_country': country_fr})
        self.assertEqual(self.partner.browse(cr, bob, partner_id).property_country.id, country_fr, "Bob does not see the value he has set on the property field")

        self.partner.write(cr, alice, [partner_id], {'property_country': country_be})
        self.assertEqual(self.partner.browse(cr, alice, partner_id).property_country.id, country_be, "Alice does not see the value he has set on the property field")
        self.assertEqual(self.partner.browse(cr, bob, partner_id).property_country.id, country_fr, "Changes made by Alice have overwritten Bob's value")
コード例 #4
0
class product_template(osv.osv):
    _name = 'product.template'
    _inherit = 'product.template'

    def _product_available(self, cr, uid, ids, name, arg, context=None):
        prod_available = {}
        product_ids = self.browse(cr, uid, ids, context=context)
        var_ids = []
        for product in product_ids:
            var_ids += [p.id for p in product.product_variant_ids]
        variant_available = self.pool['product.product']._product_available(
            cr, uid, var_ids, context=context)

        for product in product_ids:
            qty_available = 0
            virtual_available = 0
            incoming_qty = 0
            outgoing_qty = 0
            for p in product.product_variant_ids:
                qty_available += variant_available[p.id]["qty_available"]
                virtual_available += variant_available[
                    p.id]["virtual_available"]
                incoming_qty += variant_available[p.id]["incoming_qty"]
                outgoing_qty += variant_available[p.id]["outgoing_qty"]
            prod_available[product.id] = {
                "qty_available": qty_available,
                "virtual_available": virtual_available,
                "incoming_qty": incoming_qty,
                "outgoing_qty": outgoing_qty,
            }
        return prod_available

    def _search_product_quantity(self, cr, uid, obj, name, domain, context):
        prod = self.pool.get("product.product")
        product_variant_ids = prod.search(cr, uid, domain, context=context)
        return [('product_variant_ids', 'in', product_variant_ids)]

    def _product_available_text(self,
                                cr,
                                uid,
                                ids,
                                field_names=None,
                                arg=False,
                                context=None):
        res = {}
        for product in self.browse(cr, uid, ids, context=context):
            res[product.id] = str(product.qty_available) + _(" On Hand")
        return res

    def _compute_nbr_reordering_rules(self,
                                      cr,
                                      uid,
                                      ids,
                                      field_names=None,
                                      arg=None,
                                      context=None):
        res = dict.fromkeys(
            ids, {
                'nbr_reordering_rules': 0,
                'reordering_min_qty': 0,
                'reordering_max_qty': 0
            })
        product_data = self.pool['stock.warehouse.orderpoint'].read_group(
            cr,
            uid, [('product_id.product_tmpl_id', 'in', ids)],
            ['product_id', 'product_min_qty', 'product_max_qty'],
            ['product_id'],
            context=context)
        for data in product_data:
            product_tmpl_id = data['__domain'][1][2][0]
            res[product_tmpl_id][
                'nbr_reordering_rules'] = res[product_tmpl_id].get(
                    'nbr_reordering_rules', 0) + int(data['product_id_count'])
            res[product_tmpl_id]['reordering_min_qty'] = data[
                'product_min_qty']
            res[product_tmpl_id]['reordering_max_qty'] = data[
                'product_max_qty']
        return res

    def _get_product_template_type(self, cr, uid, context=None):
        res = super(product_template,
                    self)._get_product_template_type(cr, uid, context=context)
        if 'product' not in [item[0] for item in res]:
            res.append(('product', 'Producto Almacenable'))
        return res

    _columns = {
        'property_stock_procurement':
        fields.property(
            type='many2one',
            relation='stock.location',
            string="Procurement Location",
            domain=[('usage', 'like', 'procurement')],
            help=
            "This stock location will be used, instead of the default one, as the source location for stock moves generated by procurements."
        ),
        'property_stock_production':
        fields.property(
            type='many2one',
            relation='stock.location',
            string="Production Location",
            domain=[('usage', 'like', 'production')],
            help=
            "This stock location will be used, instead of the default one, as the source location for stock moves generated by manufacturing orders."
        ),
        'property_stock_inventory':
        fields.property(
            type='many2one',
            relation='stock.location',
            string="Inventory Location",
            domain=[('usage', 'like', 'inventory')],
            help=
            "This stock location will be used, instead of the default one, as the source location for stock moves generated when you do an inventory."
        ),
        'sale_delay':
        fields.float(
            'Customer Lead Time',
            help=
            "The average delay in days between the confirmation of the customer order and the delivery of the finished products. It's the time you promise to your customers."
        ),
        'tracking':
        fields.selection(selection=[('serial', 'By Unique Serial Number'),
                                    ('lot', 'By Lots'),
                                    ('none', 'No Tracking')],
                         string="Tracking",
                         required=True),
        'description_picking':
        fields.text('Description on Picking', translate=True),
        # sum of product variant qty
        # 'reception_count': fields.function(_product_available, multi='qty_available',
        #     fnct_search=_search_product_quantity, type='float', string='Quantity On Hand'),
        # 'delivery_count': fields.function(_product_available, multi='qty_available',
        #     fnct_search=_search_product_quantity, type='float', string='Quantity On Hand'),
        'qty_available':
        fields.function(
            _product_available,
            multi='qty_available',
            digits_compute=dp.get_precision('Product Unit of Measure'),
            fnct_search=_search_product_quantity,
            type='float',
            string='Quantity On Hand'),
        'virtual_available':
        fields.function(
            _product_available,
            multi='qty_available',
            digits_compute=dp.get_precision('Product Unit of Measure'),
            fnct_search=_search_product_quantity,
            type='float',
            string='Forecasted Quantity'),
        'incoming_qty':
        fields.function(
            _product_available,
            multi='qty_available',
            digits_compute=dp.get_precision('Product Unit of Measure'),
            fnct_search=_search_product_quantity,
            type='float',
            string='Incoming'),
        'outgoing_qty':
        fields.function(
            _product_available,
            multi='qty_available',
            digits_compute=dp.get_precision('Product Unit of Measure'),
            fnct_search=_search_product_quantity,
            type='float',
            string='Outgoing'),
        'location_id':
        fields.dummy(string='Location',
                     relation='stock.location',
                     type='many2one'),
        'warehouse_id':
        fields.dummy(string='Warehouse',
                     relation='stock.warehouse',
                     type='many2one'),
        'route_ids':
        fields.many2many(
            'stock.location.route',
            'stock_route_product',
            'product_id',
            'route_id',
            'Routes',
            domain="[('product_selectable', '=', True)]",
            help=
            "Depending on the modules installed, this will allow you to define the route of the product: whether it will be bought, manufactured, MTO/MTS,..."
        ),
        'nbr_reordering_rules':
        fields.function(_compute_nbr_reordering_rules,
                        string='Reordering Rules',
                        type='integer',
                        multi=True),
        'reordering_min_qty':
        fields.function(_compute_nbr_reordering_rules,
                        type='float',
                        multi=True),
        'reordering_max_qty':
        fields.function(_compute_nbr_reordering_rules,
                        type='float',
                        multi=True),
        'route_from_categ_ids':
        fields.related('categ_id',
                       'total_route_ids',
                       type="many2many",
                       relation="stock.location.route",
                       string="Category Routes"),
    }

    _defaults = {
        'sale_delay': 7,
        'tracking': 'none',
    }

    def action_view_routes(self, cr, uid, ids, context=None):
        route_obj = self.pool.get("stock.location.route")
        act_obj = self.pool.get('ir.actions.act_window')
        mod_obj = self.pool.get('ir.model.data')
        product_route_ids = set()
        for product in self.browse(cr, uid, ids, context=context):
            product_route_ids |= set([r.id for r in product.route_ids])
            product_route_ids |= set(
                [r.id for r in product.categ_id.total_route_ids])
        route_ids = route_obj.search(cr,
                                     uid, [
                                         '|',
                                         ('id', 'in', list(product_route_ids)),
                                         ('warehouse_selectable', '=', True)
                                     ],
                                     context=context)
        result = mod_obj.xmlid_to_res_id(cr,
                                         uid,
                                         'stock.action_routes_form',
                                         raise_if_not_found=True)
        result = act_obj.read(cr, uid, [result], context=context)[0]
        result['domain'] = "[('id','in',[" + ','.join(map(str,
                                                          route_ids)) + "])]"
        return result

    def onchange_tracking(self, cr, uid, ids, tracking, context=None):
        if not tracking:
            return {}
        product_product = self.pool['product.product']
        variant_ids = product_product.search(cr,
                                             uid,
                                             [('product_tmpl_id', 'in', ids)],
                                             context=context)
        return product_product.onchange_tracking(cr,
                                                 uid,
                                                 variant_ids,
                                                 tracking,
                                                 context=context)

    def _get_products(self, cr, uid, ids, context=None):
        products = []
        for prodtmpl in self.browse(cr, uid, ids, context=None):
            products += [x.id for x in prodtmpl.product_variant_ids]
        return products

    def _get_act_window_dict(self, cr, uid, name, context=None):
        mod_obj = self.pool.get('ir.model.data')
        act_obj = self.pool.get('ir.actions.act_window')
        result = mod_obj.xmlid_to_res_id(cr,
                                         uid,
                                         name,
                                         raise_if_not_found=True)
        result = act_obj.read(cr, uid, [result], context=context)[0]
        return result

    def action_open_quants(self, cr, uid, ids, context=None):
        products = self._get_products(cr, uid, ids, context=context)
        result = self._get_act_window_dict(cr,
                                           uid,
                                           'stock.product_open_quants',
                                           context=context)
        result['domain'] = "[('product_id','in',[" + ','.join(
            map(str, products)) + "])]"
        result[
            'context'] = "{'search_default_locationgroup': 1, 'search_default_internal_loc': 1}"
        return result

    def action_view_orderpoints(self, cr, uid, ids, context=None):
        products = self._get_products(cr, uid, ids, context=context)
        result = self._get_act_window_dict(cr,
                                           uid,
                                           'stock.product_open_orderpoint',
                                           context=context)
        if len(ids) == 1 and len(products) == 1:
            result['context'] = "{'default_product_id': " + str(
                products[0]) + ", 'search_default_product_id': " + str(
                    products[0]) + "}"
        else:
            result['domain'] = "[('product_id','in',[" + ','.join(
                map(str, products)) + "])]"
            result['context'] = "{}"
        return result

    def action_view_stock_moves(self, cr, uid, ids, context=None):
        products = self._get_products(cr, uid, ids, context=context)
        result = self._get_act_window_dict(cr,
                                           uid,
                                           'stock.act_product_stock_move_open',
                                           context=context)
        if products:
            result['context'] = "{'default_product_id': %d}" % products[0]
        result['domain'] = "[('product_id.product_tmpl_id','in',[" + ','.join(
            map(str, ids)) + "])]"
        return result

    def write(self, cr, uid, ids, vals, context=None):
        if 'uom_id' in vals:
            new_uom = self.pool.get('product.uom').browse(cr,
                                                          uid,
                                                          vals['uom_id'],
                                                          context=context)
            for product in self.browse(cr, uid, ids, context=context):
                old_uom = product.uom_id
                if old_uom != new_uom:
                    if self.pool.get('stock.move').search(
                            cr,
                            uid,
                        [('product_id', 'in',
                          [x.id for x in product.product_variant_ids]),
                         ('state', '=', 'done')],
                            limit=1,
                            context=context):
                        raise UserError(
                            _("You can not change the unit of measure of a product that has already been used in a done stock move. If you need to change the unit of measure, you may deactivate this product."
                              ))
        return super(product_template, self).write(cr,
                                                   uid,
                                                   ids,
                                                   vals,
                                                   context=context)
コード例 #5
0
    def test_1_property_multicompany(self):
        cr, uid = self.cr, self.uid

        parent_company_id = self.imd.get_object_reference(
            cr, uid, 'base', 'main_company')[1]
        country_be = self.imd.get_object_reference(cr, uid, 'base', 'be')[1]
        country_fr = self.imd.get_object_reference(cr, uid, 'base', 'fr')[1]
        group_partner_manager = self.imd.get_object_reference(
            cr, uid, 'base', 'group_partner_manager')[1]
        group_multi_company = self.imd.get_object_reference(
            cr, uid, 'base', 'group_multi_company')[1]

        sub_company = self.company.create(cr, uid, {
            'name': 'MegaCorp',
            'parent_id': parent_company_id
        })
        alice = self.user.create(
            cr, uid, {
                'name': 'Alice',
                'login': '******',
                'email': '*****@*****.**',
                'company_id': parent_company_id,
                'company_ids': [(6, 0, [parent_company_id, sub_company])],
                'country_id': country_be,
                'groups_id':
                [(6, 0, [group_partner_manager, group_multi_company])]
            })
        bob = self.user.create(
            cr, uid, {
                'name': 'Bob',
                'login': '******',
                'email': '*****@*****.**',
                'company_id': sub_company,
                'company_ids': [(6, 0, [parent_company_id, sub_company])],
                'country_id': country_fr,
                'groups_id':
                [(6, 0, [group_partner_manager, group_multi_company])]
            })

        self.partner._columns = dict(self.partner._columns)
        self.partner._columns.update({
            'property_country':
            fields.property(type='many2one',
                            relation="res.country",
                            string="Country by company"),
        })
        self.partner._field_create(cr)

        partner_id = self.partner.create(
            cr, alice, {
                'name': 'An International Partner',
                'email': '*****@*****.**',
                'company_id': parent_company_id,
            })
        self.partner.write(cr, bob, [partner_id],
                           {'property_country': country_fr})
        self.assertEqual(
            self.partner.browse(cr, bob,
                                partner_id).property_country.id, country_fr,
            "Bob does not see the value he has set on the property field")

        self.partner.write(cr, alice, [partner_id],
                           {'property_country': country_be})
        self.assertEqual(
            self.partner.browse(cr, alice,
                                partner_id).property_country.id, country_be,
            "Alice does not see the value he has set on the property field")
        self.assertEqual(
            self.partner.browse(cr, bob, partner_id).property_country.id,
            country_fr, "Changes made by Alice have overwritten Bob's value")
コード例 #6
0
class ir_actions_report_xml(orm.Model):
    _inherit = 'ir.actions.report.xml'
    _columns = {
        'webkit_header':
        fields.property(type='many2one',
                        relation='ir.header_webkit',
                        string='Webkit Header',
                        help="The header linked to the report",
                        required=True),
        'webkit_debug':
        fields.boolean('Webkit debug',
                       help="Enable the webkit engine debugger"),
        'report_webkit_data':
        fields.text(
            'Webkit Template',
            help=
            "This template will be used if the main report file is not found"),
        'precise_mode':
        fields.boolean(
            'Precise Mode',
            help="This mode allow more precise element position as each object"
            " is printed on a separate HTML but memory and disk usage are wider."
        )
    }

    def _lookup_report(self, cr, name):
        """
        Look up a report definition.
        """
        import operator
        import os
        opj = os.path.join

        # First lookup in the deprecated place, because if the report definition
        # has not been updated, it is more likely the correct definition is there.
        # Only reports with custom parser specified in Python are still there.
        if 'report.' + name in ecore.report.interface.report_int._reports:
            new_report = ecore.report.interface.report_int._reports['report.' +
                                                                    name]
            if not isinstance(new_report, WebKitParser):
                new_report = None
        else:
            cr.execute(
                "SELECT * FROM ir_act_report_xml WHERE report_name=%s and report_type=%s",
                (name, 'webkit'))
            r = cr.dictfetchone()
            if r:
                if r['parser']:
                    parser = operator.attrgetter(r['parser'])(ecore.addons)
                    kwargs = {'parser': parser}
                else:
                    kwargs = {}

                new_report = WebKitParser('report.' + r['report_name'],
                                          r['model'],
                                          opj('addons', r['report_rml']
                                              or '/'),
                                          header=r['header'],
                                          register=False,
                                          **kwargs)
            else:
                new_report = None

        if new_report:
            return new_report
        else:
            return super(ir_actions_report_xml, self)._lookup_report(cr, name)
コード例 #7
0
ファイル: product.py プロジェクト: ecoreos/hz
class product_template(osv.osv):
    _name = 'product.template'
    _inherit = 'product.template'

    def _get_cost_method(self, cr, uid, ids, field, args, context=None):
        res = {}
        for product in self.browse(cr, uid, ids, context=context):
            if product.property_cost_method:
                res[product.id] = product.property_cost_method
            else:
                res[product.id] = product.categ_id.property_cost_method
        return res

    def _get_valuation_type(self, cr, uid, ids, field, args, context=None):
        res = {}
        for product in self.browse(cr, uid, ids, context=context):
            if product.property_valuation:
                res[product.id] = product.property_valuation
            else:
                res[product.id] = product.categ_id.property_valuation
        return res

    def _set_cost_method(self, cr, uid, ids, name, value, arg, context=None):
        return self.write(cr,
                          uid,
                          ids, {'property_cost_method': value},
                          context=context)

    def _set_valuation_type(self,
                            cr,
                            uid,
                            ids,
                            name,
                            value,
                            arg,
                            context=None):
        return self.write(cr,
                          uid,
                          ids, {'property_valuation': value},
                          context=context)

    _columns = {
        'property_valuation': fields.property(type='selection', selection=[('manual_periodic', 'Periodic (manual)'),
                                        ('real_time', 'Perpetual (automated)')], string='Inventory Valuation',
                                        help="If perpetual valuation is enabled for a product, the system will automatically create journal entries corresponding to stock moves, with product price as specified by the 'Costing Method'" \
                                             "The inventory variation account set on the product category will represent the current inventory value, and the stock input and stock output account will hold the counterpart moves for incoming and outgoing products."
                                        , copy=True),
        'valuation': fields.function(_get_valuation_type, fnct_inv=_set_valuation_type, type='char'),  # TDE FIXME: store it ?
        'property_cost_method': fields.property(type='selection', selection=[('standard', 'Standard Price'), ('average', 'Average Price'), ('real', 'Real Price')],
            help="""Standard Price: The cost price is manually updated at the end of a specific period (usually once a year).
                    Average Price: The cost price is recomputed at each incoming shipment and used for the product valuation.
                    Real Price: The cost price displayed is the price of the last outgoing product (will be use in case of inventory loss for example).""",
            string="Costing Method", copy=True),
        'cost_method': fields.function(_get_cost_method, fnct_inv=_set_cost_method, type='char'),  # TDE FIXME: store it ?
        'property_stock_account_input': fields.property(
            type='many2one',
            relation='account.account',
            string='Stock Input Account',
            domain=[('deprecated', '=', False)],
            help="When doing real-time inventory valuation, counterpart journal items for all incoming stock moves will be posted in this account, unless "
                 "there is a specific valuation account set on the source location. When not set on the product, the one from the product category is used."),
        'property_stock_account_output': fields.property(
            type='many2one',
            relation='account.account',
            string='Stock Output Account',
            domain=[('deprecated', '=', False)],
            help="When doing real-time inventory valuation, counterpart journal items for all outgoing stock moves will be posted in this account, unless "
                 "there is a specific valuation account set on the destination location. When not set on the product, the one from the product category is used."),
    }

    _defaults = {
        'property_valuation': 'manual_periodic',
    }

    def create(self, cr, uid, vals, context=None):
        if vals.get('cost_method'):
            vals['property_cost_method'] = vals.pop('cost_method')
        if vals.get('valuation'):
            vals['property_valuation'] = vals.pop('valuation')
        return super(product_template, self).create(cr,
                                                    uid,
                                                    vals,
                                                    context=context)

    @api.onchange('type')
    def onchange_type_valuation(self):
        if self.type != 'product':
            self.valuation = 'manual_periodic'
        return {}

    @api.multi
    def _get_product_accounts(self):
        """ Add the stock accounts related to product to the result of super()
        @return: dictionary which contains information regarding stock accounts and super (income+expense accounts)
        """
        accounts = super(product_template, self)._get_product_accounts()
        accounts.update({
            'stock_input':
            self.property_stock_account_input
            or self.categ_id.property_stock_account_input_categ_id,
            'stock_output':
            self.property_stock_account_output
            or self.categ_id.property_stock_account_output_categ_id,
            'stock_valuation':
            self.categ_id.property_stock_valuation_account_id or False,
        })
        return accounts

    @api.multi
    def get_product_accounts(self, fiscal_pos=None):
        """ Add the stock journal related to product to the result of super()
        @return: dictionary which contains all needed information regarding stock accounts and journal and super (income+expense accounts)
        """
        accounts = super(product_template,
                         self).get_product_accounts(fiscal_pos=fiscal_pos)
        accounts.update(
            {'stock_journal': self.categ_id.property_stock_journal or False})
        return accounts

    def do_change_standard_price(self, cr, uid, ids, new_price, context=None):
        """ Changes the Standard Price of Product and creates an account move accordingly."""
        location_obj = self.pool.get('stock.location')
        move_obj = self.pool.get('account.move')
        if context is None:
            context = {}
        user_company_id = self.pool.get('res.users').browse(
            cr, uid, uid, context=context).company_id.id
        loc_ids = location_obj.search(cr, uid,
                                      [('usage', '=', 'internal'),
                                       ('company_id', '=', user_company_id)])
        for rec_id in ids:
            datas = self.get_product_accounts(cr, uid, rec_id, context=context)
            for location in location_obj.browse(cr,
                                                uid,
                                                loc_ids,
                                                context=context):
                c = context.copy()
                c.update({'location': location.id, 'compute_child': False})
                product = self.browse(cr, uid, rec_id, context=c)

                diff = product.standard_price - new_price
                if not diff:
                    raise UserError(
                        _("No difference between standard price and new price!"
                          ))
                for prod_variant in product.product_variant_ids:
                    qty = prod_variant.qty_available
                    if qty:
                        # Accounting Entries
                        amount_diff = abs(diff * qty)
                        if diff * qty > 0:
                            debit_account_id = datas['expense'].id
                            credit_account_id = datas['stock_valuation'].id
                        else:
                            debit_account_id = datas['stock_valuation'].id
                            credit_account_id = datas['expense'].id

                        lines = [(0, 0, {
                            'name': _('Standard Price changed'),
                            'account_id': debit_account_id,
                            'debit': amount_diff,
                            'credit': 0,
                        }),
                                 (0, 0, {
                                     'name': _('Standard Price changed'),
                                     'account_id': credit_account_id,
                                     'debit': 0,
                                     'credit': amount_diff,
                                 })]
                        move_vals = {
                            'journal_id': datas['stock_journal'].id,
                            'company_id': location.company_id.id,
                            'line_ids': lines,
                        }
                        move_id = move_obj.create(cr,
                                                  uid,
                                                  move_vals,
                                                  context=context)
                        move_obj.post(cr, uid, [move_id], context=context)
            self.write(cr, uid, rec_id, {'standard_price': new_price})
        return True
コード例 #8
0
ファイル: product.py プロジェクト: ecoreos/hz
class product_category(osv.osv):
    _inherit = 'product.category'
    _columns = {
        'property_valuation':
        fields.property(
            type='selection',
            selection=[('manual_periodic', 'Periodic (manual)'),
                       ('real_time', 'Perpetual (automated)')],
            string='Inventory Valuation',
            required=True,
            copy=True,
            help="If perpetual valuation is enabled for a product, the system "
            "will automatically create journal entries corresponding to "
            "stock moves, with product price as specified by the 'Costing "
            "Method'. The inventory variation account set on the product "
            "category will represent the current inventory value, and the "
            "stock input and stock output account will hold the counterpart "
            "moves for incoming and outgoing products."),
        'property_cost_method':
        fields.property(
            type='selection',
            selection=[('standard', 'Standard Price'),
                       ('average', 'Average Price'), ('real', 'Real Price')],
            string="Costing Method",
            required=True,
            copy=True,
            help="Standard Price: The cost price is manually updated at the end "
            "of a specific period (usually once a year).\nAverage Price: "
            "The cost price is recomputed at each incoming shipment and "
            "used for the product valuation.\nReal Price: The cost price "
            "displayed is the price of the last outgoing product (will be "
            "used in case of inventory loss for example)."
            ""),
        'property_stock_journal':
        fields.property(
            relation='account.journal',
            type='many2one',
            string='Stock Journal',
            help=
            "When doing real-time inventory valuation, this is the Accounting Journal in which entries will be automatically posted when stock moves are processed."
        ),
        'property_stock_account_input_categ_id':
        fields.property(
            type='many2one',
            relation='account.account',
            string='Stock Input Account',
            domain=[('deprecated', '=', False)],
            oldname="property_stock_account_input_categ",
            help=
            "When doing real-time inventory valuation, counterpart journal items for all incoming stock moves will be posted in this account, unless "
            "there is a specific valuation account set on the source location. This is the default value for all products in this category. It "
            "can also directly be set on each product"),
        'property_stock_account_output_categ_id':
        fields.property(
            type='many2one',
            relation='account.account',
            domain=[('deprecated', '=', False)],
            string='Stock Output Account',
            oldname="property_stock_account_output_categ",
            help=
            "When doing real-time inventory valuation, counterpart journal items for all outgoing stock moves will be posted in this account, unless "
            "there is a specific valuation account set on the destination location. This is the default value for all products in this category. It "
            "can also directly be set on each product"),
        'property_stock_valuation_account_id':
        fields.property(
            type='many2one',
            relation='account.account',
            string="Stock Valuation Account",
            domain=[('deprecated', '=', False)],
            help=
            "When real-time inventory valuation is enabled on a product, this account will hold the current value of the products.",
        ),
    }