You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Odoo 8的Invoice Line中按不同供应商分组显示产品

Hey there! Let's work through how to group invoice lines by supplier in your Odoo 8 confirmed sales orders. Here's a practical, step-by-step solution:

1. Core Context

First, Odoo's account.invoice.line (invoice lines) links to product.product (your products), which store supplier details in product.supplierinfo. We need to pull that supplier data into invoice line records so we can group by it.

2. Add a Supplier Field to Invoice Lines

We'll extend the account.invoice.line model with a computed field that fetches the product's primary supplier. Create a custom module and add this to your models.py:

from openerp.osv import osv, fields

class AccountInvoiceLine(osv.Model):
    _inherit = 'account.invoice.line'
    
    def _fetch_product_supplier(self, cr, uid, ids, field_name, arg, context=None):
        result = {}
        for line in self.browse(cr, uid, ids, context=context):
            # Grab the first supplier from the product's supplier list (adjust logic if needed)
            if line.product_id and line.product_id.seller_ids:
                result[line.id] = line.product_id.seller_ids[0].name.id
            else:
                result[line.id] = False
        return result
    
    _columns = {
        'supplier_id': fields.function(
            _fetch_product_supplier,
            type='many2one',
            relation='res.partner',
            string='Supplier',
            store=True  # Store value for better grouping performance
        ),
    }

3. Update the Invoice Line Tree View

Next, modify the tree view for invoice lines (used in confirmed sales orders) to display the supplier field and enable grouping. Add this to your views.xml:

<openerp>
    <data>
        <!-- Inherit the base invoice line tree view -->
        <record id="inherit_invoice_line_tree_supplier" model="ir.ui.view">
            <field name="name">account.invoice.line.tree.supplier.group</field>
            <field name="model">account.invoice.line</field>
            <field name="inherit_id" ref="account.view_invoice_line_tree"/>
            <field name="arch" type="xml">
                <!-- Insert supplier field right after the product name -->
                <field name="name" position="after">
                    <field name="supplier_id"/>
                </field>
                <!-- Set default grouping by supplier (users can toggle this off if needed) -->
                <tree position="attributes">
                    <attribute name="default_group_by">supplier_id</attribute>
                </tree>
            </field>
        </record>
    </data>
</openerp>

4. Finalize Your Module

Make sure to declare dependencies in __openerp__.py so the module loads after core modules:

{
    'name': 'Invoice Line Supplier Grouping',
    'version': '1.0',
    'depends': ['account', 'sale'],
    'data': ['views.xml'],
    'installable': True,
}

Quick Adjustments & Notes

  • If your products have multiple suppliers and you need to pick a specific one (not just the first), tweak the _fetch_product_supplier function. For example, if sales orders link to purchase orders, you could pull the supplier directly from the associated PO line.
  • The store=True flag saves the supplier value to the database, making grouping and filtering faster.
  • After installing the module, head to Sales > Confirmed Sales Orders, open an order with invoices, and you'll see invoice lines automatically grouped by supplier.

内容的提问来源于stack exchange,提问作者Shahjalal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:18:09