Skip to Content
Menu
This question has been flagged
1 Reply
20058 Views

Hi

I've created and displayed a simple module that creates a selection drop down menu in sales.order .... Big smiley face :)

However ...  :(

Question 1 How do I display this value in stock.picking - None editable?

Question 2 How do  I display this value in account.invoice - and editable?


from odoo import fields, models

class SaleHoldNoteModel(models.Model):
    _inherit = 'sale.order'

    #Create new field containg note for shipping
    shipping_note = fields.Selection([
        ('oktoship', 'Ship'),
        ('awaitingpayment', 'Hold')], default='oktoship')


<?xml version="1.0" encoding="utf-8" ?>

<odoo>
  <record id="add_field_shipping_sales" model="ir.ui.view">
    <field name="name">shipping_hold</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
      <xpath expr="//field[@name='payment_term_id']" position="after">
        <field name="shipping_note"/>
      </xpath>
    </field>
  </record>
</odoo>


I tried creating a copy of the above but keep getting field not known 

Do I have to transfer the field and value between models?

Odoo10rUS


Avatar
Discard
Best Answer

First of all, you need to define a link between an invoice (picking) and an order. For invoice you may use the field 'origin' or modify the function _prepare_invoice of sale.order. E.g.:

@api.multi
@api.depends("origin")
def _compute_order_id(self):
    for invoice in self:
         order_ids = self.env["sale.order"].search([("name","=",invoice.origin)])
         if len(order_ids) > 0:
invoice.order_id = order_ids[0]
order_id = fields.Many2one("sale.order",compute=_compute_order_id, store=True) 

Then, use the 'related' attribute in the corresponding models.

E.g. for 'account.invoice':

shipping_note = fields.Selection(related="order_id.shipping_note",store=True) 
#store= True means that value would be saved in an invoice as well as in a sales order and may be used as a search criteria

By default it would be editable. To make it readonly, use the standard xml attribute readonly="1"

 


Avatar
Discard
Author

Sir.

Many thanks.

I think I'm starting to understand my confusion. Some times I can get links - just by editing reports.

eg - In delivery report <t t-if="o.sale_id.partner_invoice_id.property_product_pricelist.id == 1">

But I ASSuME this is purely "luck" - because the link already exists for the purpose of "delivery"?

Related Posts Replies Views Activity
1
Feb 19
3153
2
Dec 17
14889
0
Apr 15
2727
1
Mar 15
8396
2
Sep 23
7136