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.
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="['&',
('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
has x_stock_move
, a one2many field related to an invoice via x_invoice_id
which is many2one in stock.move
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.
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.
Adding context="{'x_invoice_id':'False'}"
or False
doesn't seem to change anything.
What should I do to let a user only pick the stock.moves
that dont have an x_invoice_id
associated inside account.invoice.supplier.form
?
And here for part 2:
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')
How can I add each x_stock_move.product_id
and x_stock_move.product_qty
as an invoice line?
domain="['&', ('state','=','done'), ('picking_partner_id','=',context.get('partner_id')), '&', ('x_invoice_id','=',False)]"
– Nacho Rx_stock_move
andx_invoice_id
python code here? You're mixing "many2many" and "one2many" in your question a lot. Wouldn't be better to create the process from "the other side"? I mean creating invoices out of moves (list) or even from whole pickings. – CZoellneraccount.invoice
has fieldx_stock_move
typeone2many
objectstock.move
relx_invoice_id
stock.move
has fieldx_invoice_id
typemany2one
objectaccount.invoice
– Nacho R