mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] stock_picking_auto_print: black, isort, prettier
This commit is contained in:
@@ -3,20 +3,15 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Direct Print',
|
"name": "Direct Print",
|
||||||
'summary': 'Auto print when DO is ready',
|
"summary": "Auto print when DO is ready",
|
||||||
'version': '11.0.1.0.0',
|
"version": "11.0.1.0.0",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
|
"author": "Open Source Integrators, Odoo Community Association (OCA)",
|
||||||
'category': 'Generic Modules/Base',
|
"category": "Generic Modules/Base",
|
||||||
'website': 'http://www.opensourceintegrators.com',
|
"website": "http://www.opensourceintegrators.com",
|
||||||
'depends': [
|
"depends": ["sale_stock", "base_report_to_printer", ],
|
||||||
'sale_stock',
|
"data": ["views/ir_action_report_view.xml"],
|
||||||
'base_report_to_printer',
|
"maintainers": ["bodedra"],
|
||||||
],
|
"installable": True,
|
||||||
'data': [
|
|
||||||
'views/ir_action_report_view.xml'
|
|
||||||
],
|
|
||||||
'maintainers': ['bodedra'],
|
|
||||||
'installable': True,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ from odoo import fields, models
|
|||||||
class IrActionsReport(models.Model):
|
class IrActionsReport(models.Model):
|
||||||
_inherit = "ir.actions.report"
|
_inherit = "ir.actions.report"
|
||||||
|
|
||||||
is_default_report = fields.Boolean('Is Default Report?')
|
is_default_report = fields.Boolean("Is Default Report?")
|
||||||
country_id = fields.Many2one('res.country', string='Country')
|
country_id = fields.Many2one("res.country", string="Country")
|
||||||
company_id = fields.Many2one('res.company', string='Company')
|
company_id = fields.Many2one("res.company", string="Company")
|
||||||
|
|||||||
@@ -10,37 +10,41 @@ class StockPicking(models.Model):
|
|||||||
|
|
||||||
def _search_default_report(self, country_id=False, company_id=False):
|
def _search_default_report(self, country_id=False, company_id=False):
|
||||||
report_id = False
|
report_id = False
|
||||||
report_action_pool = self.env['ir.actions.report']
|
report_action_pool = self.env["ir.actions.report"]
|
||||||
domain = [('model', '=', 'stock.picking'),
|
domain = [("model", "=", "stock.picking"), ("is_default_report", "=", True)]
|
||||||
('is_default_report', '=', True)]
|
fields = ["country_id", "company_id"]
|
||||||
fields = ['country_id', 'company_id']
|
|
||||||
stock_picking_reports = report_action_pool.search_read(domain, fields)
|
stock_picking_reports = report_action_pool.search_read(domain, fields)
|
||||||
if country_id and company_id:
|
if country_id and company_id:
|
||||||
for value in stock_picking_reports:
|
for value in stock_picking_reports:
|
||||||
if value.get('country_id') and value.get('company_id'):
|
if value.get("country_id") and value.get("company_id"):
|
||||||
if value.get('country_id')[0] == country_id and \
|
if (
|
||||||
value.get('company_id')[0] == company_id:
|
value.get("country_id")[0] == country_id
|
||||||
return value['id']
|
and value.get("company_id")[0] == company_id
|
||||||
|
):
|
||||||
|
return value["id"]
|
||||||
elif country_id:
|
elif country_id:
|
||||||
for value in stock_picking_reports:
|
for value in stock_picking_reports:
|
||||||
if value.get('country_id'):
|
if value.get("country_id"):
|
||||||
if value.get('country_id')[0] == country_id:
|
if value.get("country_id")[0] == country_id:
|
||||||
return value['id']
|
return value["id"]
|
||||||
elif company_id:
|
elif company_id:
|
||||||
for value in stock_picking_reports:
|
for value in stock_picking_reports:
|
||||||
if value.get('company_id'):
|
if value.get("company_id"):
|
||||||
if value.get('company_id')[0] == company_id:
|
if value.get("company_id")[0] == company_id:
|
||||||
return value['id']
|
return value["id"]
|
||||||
else:
|
else:
|
||||||
report_id = self.env.ref(
|
report_id = (
|
||||||
'stock.action_report_picking').with_context(
|
self.env.ref("stock.action_report_picking")
|
||||||
landscape=True).report_action(self).get('id')
|
.with_context(landscape=True)
|
||||||
|
.report_action(self)
|
||||||
|
.get("id")
|
||||||
|
)
|
||||||
return report_id
|
return report_id
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _stock_picking_default_auto_print_report(self):
|
def _stock_picking_default_auto_print_report(self):
|
||||||
user_company_id = self.env.user.company_id.id
|
user_company_id = self.env.user.company_id.id
|
||||||
report_action_pool = self.env['ir.actions.report']
|
report_action_pool = self.env["ir.actions.report"]
|
||||||
for picking in self.filtered(lambda p: p.sale_id):
|
for picking in self.filtered(lambda p: p.sale_id):
|
||||||
default_report_id = False
|
default_report_id = False
|
||||||
# Check Partner country id
|
# Check Partner country id
|
||||||
@@ -51,24 +55,26 @@ class StockPicking(models.Model):
|
|||||||
if country_id and user_company_id:
|
if country_id and user_company_id:
|
||||||
# Filter report with Country and Company
|
# Filter report with Country and Company
|
||||||
default_report_id = picking._search_default_report(
|
default_report_id = picking._search_default_report(
|
||||||
country_id, user_company_id)
|
country_id, user_company_id
|
||||||
|
)
|
||||||
|
|
||||||
if not default_report_id and country_id:
|
if not default_report_id and country_id:
|
||||||
# Filter report with Country
|
# Filter report with Country
|
||||||
default_report_id = picking._search_default_report(
|
default_report_id = picking._search_default_report(
|
||||||
country_id=country_id)
|
country_id=country_id
|
||||||
|
)
|
||||||
|
|
||||||
if not default_report_id:
|
if not default_report_id:
|
||||||
# Filter report with Company
|
# Filter report with Company
|
||||||
default_report_id = picking._search_default_report(
|
default_report_id = picking._search_default_report(
|
||||||
company_id=user_company_id)
|
company_id=user_company_id
|
||||||
|
)
|
||||||
|
|
||||||
if not default_report_id:
|
if not default_report_id:
|
||||||
# Search for default picking operation report
|
# Search for default picking operation report
|
||||||
default_report_id = picking._search_default_report()
|
default_report_id = picking._search_default_report()
|
||||||
|
|
||||||
action_report = report_action_pool.browse(
|
action_report = report_action_pool.browse(default_report_id)
|
||||||
default_report_id)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
action_report.print_document(picking.id)
|
action_report.print_document(picking.id)
|
||||||
@@ -79,7 +85,7 @@ class StockPicking(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
res = super(StockPicking, self).write(vals)
|
res = super(StockPicking, self).write(vals)
|
||||||
if 'date_done' in vals:
|
if "date_done" in vals:
|
||||||
self._stock_picking_default_auto_print_report()
|
self._stock_picking_default_auto_print_report()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@@ -87,8 +93,9 @@ class StockPicking(models.Model):
|
|||||||
def action_assign(self):
|
def action_assign(self):
|
||||||
res = super(StockPicking, self).action_assign()
|
res = super(StockPicking, self).action_assign()
|
||||||
for picking in self:
|
for picking in self:
|
||||||
if (picking.picking_type_code == 'outgoing' or
|
if (
|
||||||
picking.location_dest_id.name == 'Output') and \
|
picking.picking_type_code == "outgoing"
|
||||||
picking.state == 'assigned':
|
or picking.location_dest_id.name == "Output"
|
||||||
|
) and picking.state == "assigned":
|
||||||
picking._stock_picking_default_auto_print_report()
|
picking._stock_picking_default_auto_print_report()
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -9,45 +9,60 @@ class StockPikcing(TransactionCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(StockPikcing, self).setUp()
|
super(StockPikcing, self).setUp()
|
||||||
|
|
||||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
self.stock_location = self.env.ref("stock.stock_location_stock")
|
||||||
self.customer_location = self.env.ref('stock.stock_location_customers')
|
self.customer_location = self.env.ref("stock.stock_location_customers")
|
||||||
self.scrapped_location = self.env.ref('stock.stock_location_scrapped')
|
self.scrapped_location = self.env.ref("stock.stock_location_scrapped")
|
||||||
|
|
||||||
uom_unit = self.env.ref('product.product_uom_unit')
|
uom_unit = self.env.ref("product.product_uom_unit")
|
||||||
|
|
||||||
self.product_A = self.env['product.product'].create({
|
self.product_A = self.env["product.product"].create(
|
||||||
'name': 'Product A',
|
{
|
||||||
'type': 'product',
|
"name": "Product A",
|
||||||
'list_price': 1.0,
|
"type": "product",
|
||||||
'categ_id': self.env.ref('product.product_category_all').id,
|
"list_price": 1.0,
|
||||||
'uom_id': uom_unit.id
|
"categ_id": self.env.ref("product.product_category_all").id,
|
||||||
})
|
"uom_id": uom_unit.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.country_us = self.env['res.country'].search(
|
self.country_us = self.env["res.country"].search(
|
||||||
[('code', 'like', 'US')], limit=1)
|
[("code", "like", "US")], limit=1
|
||||||
self.partner = self.env['res.partner'].create(
|
)
|
||||||
{'name': 'BOdedra', 'country_id': self.country_us.id})
|
self.partner = self.env["res.partner"].create(
|
||||||
|
{"name": "BOdedra", "country_id": self.country_us.id}
|
||||||
|
)
|
||||||
|
|
||||||
self.so = self.env['sale.order'].create({
|
self.so = self.env["sale.order"].create(
|
||||||
'partner_id': self.partner.id,
|
{
|
||||||
'partner_invoice_id': self.partner.id,
|
"partner_id": self.partner.id,
|
||||||
'partner_shipping_id': self.partner.id,
|
"partner_invoice_id": self.partner.id,
|
||||||
'order_line': [(0, 0, {'name': self.product_A.name,
|
"partner_shipping_id": self.partner.id,
|
||||||
'product_id': self.product_A.id,
|
"order_line": [
|
||||||
'product_uom_qty': 2,
|
(
|
||||||
'product_uom': self.product_A.uom_id.id,
|
0,
|
||||||
'price_unit': self.product_A.list_price})],
|
0,
|
||||||
'pricelist_id': self.env.ref('product.list0').id,
|
{
|
||||||
'picking_policy': 'direct',
|
"name": self.product_A.name,
|
||||||
})
|
"product_id": self.product_A.id,
|
||||||
|
"product_uom_qty": 2,
|
||||||
|
"product_uom": self.product_A.uom_id.id,
|
||||||
|
"price_unit": self.product_A.list_price,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
"pricelist_id": self.env.ref("product.list0").id,
|
||||||
|
"picking_policy": "direct",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.uom_unit = self.env.ref('product.product_uom_unit')
|
self.uom_unit = self.env.ref("product.product_uom_unit")
|
||||||
|
|
||||||
def test_stock_picking_auto_print(self):
|
def test_stock_picking_auto_print(self):
|
||||||
""" Auto print when DO is ready or done
|
""" Auto print when DO is ready or done
|
||||||
"""
|
"""
|
||||||
self.env['stock.quant']._update_available_quantity(
|
self.env["stock.quant"]._update_available_quantity(
|
||||||
self.product_A, self.stock_location, 2)
|
self.product_A, self.stock_location, 2
|
||||||
|
)
|
||||||
self.so.action_confirm()
|
self.so.action_confirm()
|
||||||
for picking in self.so.picking_ids:
|
for picking in self.so.picking_ids:
|
||||||
picking.move_lines._do_unreserve()
|
picking.move_lines._do_unreserve()
|
||||||
@@ -56,15 +71,17 @@ class StockPikcing(TransactionCase):
|
|||||||
picking.move_lines._do_unreserve()
|
picking.move_lines._do_unreserve()
|
||||||
|
|
||||||
# Made Delivery Slip report as a default report
|
# Made Delivery Slip report as a default report
|
||||||
deliveryslip_report = self.env['ir.actions.report'].search(
|
deliveryslip_report = self.env["ir.actions.report"].search(
|
||||||
[('report_name', '=', 'stock.report_deliveryslip')])
|
[("report_name", "=", "stock.report_deliveryslip")]
|
||||||
|
)
|
||||||
|
|
||||||
deliveryslip_report.write({'is_default_report': True})
|
deliveryslip_report.write({"is_default_report": True})
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
|
|
||||||
# Remove country ID from Delivery Slip report
|
# Remove country ID from Delivery Slip report
|
||||||
deliveryslip_report.write({'country_id': self.country_us.id,
|
deliveryslip_report.write(
|
||||||
'company_id': False})
|
{"country_id": self.country_us.id, "company_id": False}
|
||||||
|
)
|
||||||
picking.action_confirm()
|
picking.action_confirm()
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
|
|
||||||
@@ -75,8 +92,8 @@ class StockPikcing(TransactionCase):
|
|||||||
|
|
||||||
# Remove company ID from Delivery Slip report
|
# Remove company ID from Delivery Slip report
|
||||||
deliveryslip_report.write(
|
deliveryslip_report.write(
|
||||||
{'company_id': self.env.user.company_id.id,
|
{"company_id": self.env.user.company_id.id, "country_id": False}
|
||||||
'country_id': False})
|
)
|
||||||
picking.action_confirm()
|
picking.action_confirm()
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
|
|
||||||
@@ -84,8 +101,11 @@ class StockPikcing(TransactionCase):
|
|||||||
picking.move_lines._do_unreserve()
|
picking.move_lines._do_unreserve()
|
||||||
|
|
||||||
deliveryslip_report.write(
|
deliveryslip_report.write(
|
||||||
{'company_id': self.env.user.company_id.id,
|
{
|
||||||
'country_id': self.country_us.id})
|
"company_id": self.env.user.company_id.id,
|
||||||
|
"country_id": self.country_us.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
picking.action_confirm()
|
picking.action_confirm()
|
||||||
picking.action_assign()
|
picking.action_assign()
|
||||||
picking.action_done()
|
picking.action_done()
|
||||||
|
|||||||
Reference in New Issue
Block a user