Skip to Content
Menu
This question has been flagged

Hi, Im trying to create a related field in

sale_stock module (sale_order.py):            (the text in bold is mine)


class SaleOrder(models.Model):

    _inherit = "sale.order"


    picking_id = fields.Many2one('stock.picking', 'PickingState') #,store=True 

    picking_state = fields.Selection(related='picking_id.state', string='Picking State')     


    @api.model

    def _picking_state_done(self):

        _logger.info(self.picking_state)

        # if self.picking_state == "done":

        #     return True

        # else:

        #     return False

        return True


    warehouse_id = fields.Many2one('stock.warehouse', string='Warehouse',

        required=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},

        readonly=_picking_state_done, default=_default_warehouse_id)


stock module (stock_picking.py):


class Picking(models.Model):

    _name = "stock.picking"

    _description = "Transfer"

    state = fields.Selection([('draft', 'Draft'),...,('done', 'Done')], string='Status', compute='_compute_state',copy=False, index=True, readonly=True, store=True, track_visibility='onchange')


and I get this Error:

File "/opt/odoo/server/odoo/models.py", line 1083, in _validate_fields

    raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))

ParseError: "Error while validating constraint


'Environment' object has no attribute 'picking_state'

None" while parsing /opt/odoo/server/addons/sale_stock/views/sale_order_views.xml:4, near

<record id="view_order_form_inherit_sale_stock" model="ir.ui.view">

            <field name="name">sale.order.form.sale.stock</field>

            <field name="model">sale.order</field>

            <field name="inherit_id" ref="sale.view_order_form"/>

            <field name="arch" type="xml">

                <data><xpath expr="//button[@name='action_view_invoice']" position="before">

                    <field name="picking_ids" invisible="1"/>

                    <button type="object" name="action_view_delivery" class="oe_stat_button" icon="fa-truck" attrs="{'invisible': [('delivery_count', '=', 0)]}" groups="base.group_user">

                        <field name="delivery_count" widget="statinfo" string="Delivery"/>

                    </button>

                </xpath>

                <xpath expr="//group[@name='sales_person']" position="before">

                    <group string="Shipping Information" name="sale_shipping">

                        <!-- // JP INICIO -->

                        <!-- <field name="picking_state" invisible="1"/> -->

                        <!-- // JP INICIO -->

                        <field name="warehouse_id" options="{'no_create': True, 'no_open': True}" groups="stock.group_stock_multi_locations"/> <!-- modifiers="{'readonly': [['state', 'not in', ['draft','sent,'sale]]]}" -->

                        <field name="incoterm" widget="selection" groups="base.group_user"/>

                        <field name="picking_policy" required="True"/>

                    </group>

                </xpath>

                <xpath expr="//page/field[@name='order_line']/form/group/group/field[@name='tax_id']" position="before">

                    <field name="product_tmpl_id" invisible="1"/>

                    <field name="product_packaging" context="{'default_product_tmpl_id': product_tmpl_id, 'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id}" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging"/>

                </xpath>

                <xpath expr="//field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before">

                    <field name="route_id" groups="sale_stock.group_route_so_lines"/>

                </xpath>

                <xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="before">

                    <field name="route_id" groups="sale_stock.group_route_so_lines"/>

                </xpath>

           </data></field>

        </record>



Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
25096
2
May 24
5519
3
Mar 24
4964
0
Mar 24
262
3
Feb 24
11421