Browse Source

better way ok for bills

pull/134/head
devCbssolutionsRo 6 years ago
parent
commit
2677f010ef
  1. 83
      invoice_stock_move/models/invoice_stock.py
  2. 12
      invoice_stock_move/views/invoice_stock_move_view.xml

83
invoice_stock_move/models/invoice_stock.py

@ -21,67 +21,55 @@
############################################################################# #############################################################################
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo import models, fields, api, _ from odoo import models, fields, api, _
#from odoo.doc._extensions.pyjsparser.parser import false
class InvoiceStockMove(models.Model): class InvoiceStockMove(models.Model):
_inherit = 'account.move' _inherit = 'account.move'
@api.onchange('type') @api.onchange('type','invoice_line_ids')
def onchange_invoice_type(self): def onchange_invoice_type(self):
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']: if self.type in ['out_invoice','out_receipt']:
domain="[('code','=','incoming')]" domain=[('code','=','outgoing')]
else: elif self.type in ['in_invoice','in_receipt']:
domain="[('code','=','outgoing')]" domain=[('code','=','incoming')]
return {'domain': {'picking_type_id': domain}} if not self.picking_type_id:
@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'] type_obj = self.env['stock.picking.type']
company_id = self.env.context.get('company_id') or self.env.user.company_id.id 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) full_domain = domain+ [('warehouse_id.company_id', '=', company_id)]
if not types: self.picking_type_id = type_obj.search(full_domain, limit=1)
types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id', '=', False)]) # types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)])
return types[:4] return {'domain': {'picking_type_id': domain}}
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) invoice_picking_id = fields.Many2one('stock.picking', string="Picking Id",copy=False)
picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=True, picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=False,
default=_default_picking_receive,
help="This will determine picking type of incoming shipment",copy=False) help="This will determine picking type of incoming shipment",copy=False)
picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True, # 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)
help="This will determine picking type of outgoing shipment",copy=False) # state = fields.Selection([
state = fields.Selection([ # ('draft', 'Draft'),
('draft', 'Draft'), # ('proforma', 'Pro-forma'),
('proforma', 'Pro-forma'), # ('proforma2', 'Pro-forma'),
('proforma2', 'Pro-forma'), # ('posted', 'Posted'),
('posted', 'Posted'), # ('post', 'Post'),
('post', 'Post'), # ('cancel', 'Cancelled'),
('cancel', 'Cancelled'), # ('done', 'Received'),
('done', 'Received'), # ], string='Status', index=True, readonly=True, default='draft',
], string='Status', index=True, readonly=True, default='draft', # track_visibility='onchange', copy=False)
track_visibility='onchange', copy=False)
def action_stock_move(self): def action_stock_move(self):
"will be executed at the pressing of transfer button" "will be executed at the pressing of transfer button"
for order in self: # order is account.move meaning also invoice for order in self: # order is account.move meaning also invoice
exist_stockable_products = False if not self.invoice_picking_id:
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:
pick = { pick = {
'picking_type_id': self.picking_type_id.id, 'picking_type_id': self.picking_type_id.id,
'partner_id': self.partner_id.id, 'partner_id': self.partner_id.id,
@ -91,14 +79,11 @@ class InvoiceStockMove(models.Model):
} }
picking = self.env['stock.picking'].create(pick) picking = self.env['stock.picking'].create(pick)
self.invoice_picking_id = picking.id 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) moves = order.invoice_line_ids.filtered(lambda r: r.product_id.type in ['product'])._create_stock_moves(picking)
#, 'consu' #, 'consu'
move_ids = moves._action_confirm() move_ids = moves._action_confirm()
move_ids._action_assign() move_ids._action_assign()
else:
self.invoice_picking_id = false
self.picking_count = 0
def action_view_picking(self): def action_view_picking(self):
action = self.env.ref('stock.action_picking_tree_ready') action = self.env.ref('stock.action_picking_tree_ready')

12
invoice_stock_move/views/invoice_stock_move_view.xml

@ -8,20 +8,20 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//header" position="inside"> <xpath expr="//header" position="inside">
<button name="action_stock_move" string="Transfer" type="object" class="oe_highlight" <button name="action_stock_move" string="Transfer" type="object" class="oe_highlight"
attrs="{'invisible':['|',('state', '=', 'draft'),('picking_count', '=', 0)]}"/> attrs="{'invisible':['|',('state', '=', 'draft'),('transfer_state', '!=', 'not_done')]}"/>
</xpath> </xpath>
<xpath expr="//field[@name='invoice_date']" position="after"> <xpath expr="//field[@name='invoice_date']" position="after">
<field name="picking_type_id" /> <field name="picking_type_id" attrs="{'invisible':[('transfer_state','=','nothing_to_transfer')],'readonly':[('state','not in',['draft'])]}"/>
<field name="invoice_picking_id" invisible="0" readonly="1" force_save="1"/> <field name="transfer_state" invisible="1"/>
</xpath> </xpath>
<xpath expr="//field[@name='name']" position="before"> <xpath expr="//field[@name='name']" position="before">
<div class="oe_button_box" name="button_box"> <div class="oe_button_box" name="button_box">
<button type="object" <button type="object"
name="action_view_picking" states="open,paid" name="action_view_picking" states="open,paid"
class="oe_stat_button" attrs="{'invisible':['|',('state','=','draft'),('picking_count', '&lt;', 1)]}" class="oe_stat_button" attrs="{'invisible':['|',('state','=','draft'),('transfer_state', '!=', 'done')]}"
icon="fa-truck"> icon="fa-truck">
<field name="picking_count" string="Shipment" widget="statinfo"/> <!-- <field name="transfer_state" string="Shipment" widget="statinfo"/>
</button> --> </button>
</div> </div>
</xpath> </xpath>
</field> </field>

Loading…
Cancel
Save