diff --git a/invoice_stock_move/models/invoice_stock.py b/invoice_stock_move/models/invoice_stock.py index fc8b21fce..f665e7524 100644 --- a/invoice_stock_move/models/invoice_stock.py +++ b/invoice_stock_move/models/invoice_stock.py @@ -21,67 +21,55 @@ ############################################################################# from odoo.exceptions import UserError from odoo import models, fields, api, _ -#from odoo.doc._extensions.pyjsparser.parser import false class InvoiceStockMove(models.Model): _inherit = 'account.move' - @api.onchange('type') + @api.onchange('type','invoice_line_ids') def onchange_invoice_type(self): - if self.type in ['out_invoice','out_receipt']: - domain="[('code','=','incoming')]" - else: - domain="[('code','=','outgoing')]" + transfer_state = 'nothing_to_transfer' + for line in self.invoice_line_ids: + if line.product_id: + if line.product_id.type == 'product': + transfer_state = 'not_done' + break + self.transfer_state = transfer_state + domain=[('id','=',0)] + if transfer_state == 'not_done': + if self.type in ['out_invoice','out_receipt']: + domain=[('code','=','outgoing')] + elif self.type in ['in_invoice','in_receipt']: + domain=[('code','=','incoming')] + if not self.picking_type_id: + type_obj = self.env['stock.picking.type'] + company_id = self.env.context.get('company_id') or self.env.user.company_id.id + full_domain = domain+ [('warehouse_id.company_id', '=', company_id)] + self.picking_type_id = type_obj.search(full_domain, limit=1) + # types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)]) return {'domain': {'picking_type_id': domain}} - - @api.model - def _default_picking_receive(self): - type_obj = self.env['stock.picking.type'] - company_id = self.env.context.get('company_id') or self.env.user.company_id.id - types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], limit=1) - if not types: - types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)]) - return types[:1] - @api.model - def _default_picking_transfer(self): - type_obj = self.env['stock.picking.type'] - company_id = self.env.context.get('company_id') or self.env.user.company_id.id - types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id.company_id', '=', company_id)], limit=1) - if not types: - types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id', '=', False)]) - return types[:4] - - picking_count = fields.Integer(string="Count",copy=False) + transfer_state = fields.Selection([('not_done','not_done'),('nothing_to_transfer','nothing_to_transfer'),('done','done')],help='If the tranfer form invoice was done or not') invoice_picking_id = fields.Many2one('stock.picking', string="Picking Id",copy=False) - picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=True, - default=_default_picking_receive, + picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=False, help="This will determine picking type of incoming shipment",copy=False) - picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True, - default=_default_picking_transfer, - help="This will determine picking type of outgoing shipment",copy=False) - state = fields.Selection([ - ('draft', 'Draft'), - ('proforma', 'Pro-forma'), - ('proforma2', 'Pro-forma'), - ('posted', 'Posted'), - ('post', 'Post'), - ('cancel', 'Cancelled'), - ('done', 'Received'), - ], string='Status', index=True, readonly=True, default='draft', - track_visibility='onchange', copy=False) +# picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True, +# help="This will determine picking type of outgoing shipment",copy=False) +# state = fields.Selection([ +# ('draft', 'Draft'), +# ('proforma', 'Pro-forma'), +# ('proforma2', 'Pro-forma'), +# ('posted', 'Posted'), +# ('post', 'Post'), +# ('cancel', 'Cancelled'), +# ('done', 'Received'), +# ], string='Status', index=True, readonly=True, default='draft', +# track_visibility='onchange', copy=False) def action_stock_move(self): "will be executed at the pressing of transfer button" for order in self: # order is account.move meaning also invoice - exist_stockable_products = False - for line in order.invoice_line_ids: - if line.product_id: - if line.product_id.type == 'product': - exist_stockable_products = True - break - if exist_stockable_products and not self.invoice_picking_id: + if not self.invoice_picking_id: pick = { 'picking_type_id': self.picking_type_id.id, 'partner_id': self.partner_id.id, @@ -91,14 +79,11 @@ class InvoiceStockMove(models.Model): } picking = self.env['stock.picking'].create(pick) self.invoice_picking_id = picking.id - self.picking_count = len(picking) + self.transfer_state = 'done' moves = order.invoice_line_ids.filtered(lambda r: r.product_id.type in ['product'])._create_stock_moves(picking) #, 'consu' move_ids = moves._action_confirm() move_ids._action_assign() - else: - self.invoice_picking_id = false - self.picking_count = 0 def action_view_picking(self): action = self.env.ref('stock.action_picking_tree_ready') diff --git a/invoice_stock_move/views/invoice_stock_move_view.xml b/invoice_stock_move/views/invoice_stock_move_view.xml index c70639435..a34db501d 100644 --- a/invoice_stock_move/views/invoice_stock_move_view.xml +++ b/invoice_stock_move/views/invoice_stock_move_view.xml @@ -8,20 +8,20 @@ +