odoo通过库存变动构成发票 [英] odoo compose invoice from stock moves

查看:78
本文介绍了odoo通过库存变动构成发票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试和寻找解决问题的方法,但是由于有任何帮助,我无法找到任何解决方法.

I've been testing and searching for a solution to my problem but I'm not able to find any, thanks in advance to anyone that helps.

在Odoo 11中,我试图通过库存移动为供应商创建发票,因此我在 account.invoice.supplier.form 的笔记本表中添加了一个树形视图,如下所示:

In Odoo 11 I'm trying to build invoices for suppliers from stock moves so I've added a tree view inside a notebook sheet to account.invoice.supplier.form that looks like this:

<field name="x_stock_move" widget="many2many" options="{'no_create': True}" domain="['&amp;',
  ('state','=','done'), ('picking_partner_id','=',context.get('partner_id'))]" 
  attrs="{'readonly':[('state','not in',('draft',))]}">
  <tree>
    <field name="state" invisible="1"/> 
    <field name="date" />
    <field name="picking_partner_id" invisible="1"/>
    <field name="reference" />
    <field name="product_id" />
    <field name="product_uom_qty" string="Cantidad" />
    <field name="product_uom" />
  </tree>
</field>

account.invoice 具有 x_stock_move ,这是一个通过 x_invoice_id 与发票相关的一个字段,在 stock.move

account.invoice has x_stock_move, a one2many field related to an invoice via x_invoice_id which is many2one in stock.move

我的问题是在(在account.invoice.supplier.form字段x_stock_move中)单击添加元素"时出现的:我可以看到状态为完成"的所有stock.moves.并具有与发票中所选伙伴相同的伙伴,但是我还可以选择分配给另一张发票的stock.movs ,这应该是不可能的.

My problem comes when (in account.invoice.supplier.form field x_stock_move) I click "add an element": I can see all the stock.moves whose status is "done" and have the same partner as the one selected in the invoice but I can also select the stock.moves that are assigned to another invoice and this should not be possible.

我尝试将域 [('x_invoice_id','=','False')] 添加到字段 x_stock_move 中,但这会修改​​ account.invoice.supplier.form 而不是添加元素"表格,这样我就无法将库存变动添加到发票中.

I've tryied adding domain [('x_invoice_id','=','False')] to the field x_stock_move but this modifies the tree view inside account.invoice.supplier.form and not the "add an element" form, this way I can't add stock moves to invoices.

添加 context =''"{'x_invoice_id':'False'}'' False 似乎没有任何改变.

Adding context="{'x_invoice_id':'False'}" or False doesn't seem to change anything.

我应该怎么做才能让用户只选择在 account.invoice.supplier中没有关联 x_invoice_id stock.moves .表格?

这里是第2部分的地方:

如何在创建的发票中将 x_stock_move 中的每条记录添加为 invoice_line_id ?(我宁愿只编辑xml视图 account.invoice.supplier.form 或不必开发自定义模块来执行此操作)

How can I add each record from x_stock_move as an invoice_line_id in the invoice I'm creating? (I'd rather to do this just editing the xml view account.invoice.supplier.form or without having to develop a custom module)

感谢您走到这一步,希望您过得愉快:)

Thanks for reaching this far and hope you have a nice day :)

为了简化一点,我最终开发了一个模块,这是我的模型描述:

To simplify a bit I've ended up developing a module, here is my model description:

class Move(models.Model):
    _inherit = 'stock.move'


    x_invoice_id = fields.Many2one('account.invoice',
        string="Factura de referencia", ondelete='set null')


class Invoice(models.Model):
    _inherit = 'account.invoice'

    x_stock_move = fields.One2many('stock.move',
        string="Movimiento asociado",'x_invoice_id')

如何将每个 x_stock_move.product_id x_stock_move.product_qty 添加为发票行?

How can I add each x_stock_move.product_id and x_stock_move.product_qty as an invoice line?

推荐答案

您可以通过向导来执行此操作,该向导在单击操作以打开向导时会获取发票的active_id.参见我下面的示例(未经测试,但您会明白的)

You can do this by a wizard that takes the active_id of the invoice when clicking on an action to open the wizard. See my below example (Not Tested but you will get the concept)

stock_move_invoice_wizard.xml

stock_move_invoice_wizard.xml

<record model="ir.ui.view" id="stock_move_invoice_wizard">
    <field name="name">Stock Move Invoice</field>
    <field name="model">stock.move.invoice.wizard</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="Stock Move Invoice">
            <group>
                <field name="invocie_id"/>
            </group>
            <group>
                <field name="moves_ids"/>
            </group>
            <footer>
                <button name="action_update_moves_date" string="Link moves to invocie" type="object" class="oe_highlight"/>
                <button string="Cancel" special="cancel"/>
            </footer>
        </form>
    </field>
</record>

并在同一文件中添加操作以调用向导

and in the same file add the action to call the wizard

<act_window id="action_stock_move_invoice_wizard"
            name="Stock Move Invoice"
            res_model="stock.move.invoice.wizard"
            context="{'default_invoice_id': active_id}"
            view_mode="form"
            target="new"/>

stock_move_invoice_wizard.py

stock_move_invoice_wizard.py

class StockMoveInvoiceWizard(models.TransientModel):
    _name = 'stock.move.invoice.wizard'

    invoice_id = fields.Many2one('account.invoice', readonly=True)
    moves_ids = fields.Many2many('stock.move')

    def action_update_moves_invoice(self):
        for rec in self:
            for move in rec.moves_ids:
                move.x_invoice_id = rec.invoice_id.id

account_invoice.xml

account_invoice.xml

<record id="account_invoice_form_inherit" model="ir.ui.view">
    <field name="name">account.invoice.form.inherit</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="put_here_the_move_view_external_id"/>
    <field name="arch" type="xml">
        <xpath expr="//button[@name='action_cancel']" position="after">
            <button name="%(your_module_external_id.action_stock_move_invoice_wizard)d" string="Link Stock Moves" type="action"/>
        </xpath>
    </field>
</record>

这篇关于odoo通过库存变动构成发票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆