From 1fcec0a73abc1ecee289d386401f9f8376e5d757 Mon Sep 17 00:00:00 2001 From: Bhavesh Odedra Date: Thu, 2 Apr 2020 22:23:14 +0530 Subject: [PATCH] [IMP] stock_picking_auto_print: black, isort, prettier --- stock_picking_auto_print/__manifest__.py | 27 +++-- .../models/ir_actions_report.py | 6 +- .../models/stock_picking.py | 61 +++++++----- .../tests/test_stock_picking_auto_print.py | 98 +++++++++++-------- .../views/ir_action_report_view.xml | 10 +- 5 files changed, 112 insertions(+), 90 deletions(-) diff --git a/stock_picking_auto_print/__manifest__.py b/stock_picking_auto_print/__manifest__.py index a8c07ac..85398b8 100644 --- a/stock_picking_auto_print/__manifest__.py +++ b/stock_picking_auto_print/__manifest__.py @@ -3,20 +3,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Direct Print', - 'summary': 'Auto print when DO is ready', - 'version': '11.0.1.0.0', - 'license': 'AGPL-3', - 'author': 'Open Source Integrators, Odoo Community Association (OCA)', - 'category': 'Generic Modules/Base', - 'website': 'http://www.opensourceintegrators.com', - 'depends': [ - 'sale_stock', - 'base_report_to_printer', - ], - 'data': [ - 'views/ir_action_report_view.xml' - ], - 'maintainers': ['bodedra'], - 'installable': True, + "name": "Direct Print", + "summary": "Auto print when DO is ready", + "version": "11.0.1.0.0", + "license": "AGPL-3", + "author": "Open Source Integrators, Odoo Community Association (OCA)", + "category": "Generic Modules/Base", + "website": "http://www.opensourceintegrators.com", + "depends": ["sale_stock", "base_report_to_printer", ], + "data": ["views/ir_action_report_view.xml"], + "maintainers": ["bodedra"], + "installable": True, } diff --git a/stock_picking_auto_print/models/ir_actions_report.py b/stock_picking_auto_print/models/ir_actions_report.py index 88dabc7..7a81c8e 100644 --- a/stock_picking_auto_print/models/ir_actions_report.py +++ b/stock_picking_auto_print/models/ir_actions_report.py @@ -8,6 +8,6 @@ from odoo import fields, models class IrActionsReport(models.Model): _inherit = "ir.actions.report" - is_default_report = fields.Boolean('Is Default Report?') - country_id = fields.Many2one('res.country', string='Country') - company_id = fields.Many2one('res.company', string='Company') + is_default_report = fields.Boolean("Is Default Report?") + country_id = fields.Many2one("res.country", string="Country") + company_id = fields.Many2one("res.company", string="Company") diff --git a/stock_picking_auto_print/models/stock_picking.py b/stock_picking_auto_print/models/stock_picking.py index 230c7cf..4692909 100644 --- a/stock_picking_auto_print/models/stock_picking.py +++ b/stock_picking_auto_print/models/stock_picking.py @@ -10,37 +10,41 @@ class StockPicking(models.Model): def _search_default_report(self, country_id=False, company_id=False): report_id = False - report_action_pool = self.env['ir.actions.report'] - domain = [('model', '=', 'stock.picking'), - ('is_default_report', '=', True)] - fields = ['country_id', 'company_id'] + report_action_pool = self.env["ir.actions.report"] + domain = [("model", "=", "stock.picking"), ("is_default_report", "=", True)] + fields = ["country_id", "company_id"] stock_picking_reports = report_action_pool.search_read(domain, fields) if country_id and company_id: for value in stock_picking_reports: - if value.get('country_id') and value.get('company_id'): - if value.get('country_id')[0] == country_id and \ - value.get('company_id')[0] == company_id: - return value['id'] + if value.get("country_id") and value.get("company_id"): + if ( + value.get("country_id")[0] == country_id + and value.get("company_id")[0] == company_id + ): + return value["id"] elif country_id: for value in stock_picking_reports: - if value.get('country_id'): - if value.get('country_id')[0] == country_id: - return value['id'] + if value.get("country_id"): + if value.get("country_id")[0] == country_id: + return value["id"] elif company_id: for value in stock_picking_reports: - if value.get('company_id'): - if value.get('company_id')[0] == company_id: - return value['id'] + if value.get("company_id"): + if value.get("company_id")[0] == company_id: + return value["id"] else: - report_id = self.env.ref( - 'stock.action_report_picking').with_context( - landscape=True).report_action(self).get('id') + report_id = ( + self.env.ref("stock.action_report_picking") + .with_context(landscape=True) + .report_action(self) + .get("id") + ) return report_id @api.multi def _stock_picking_default_auto_print_report(self): 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): default_report_id = False # Check Partner country id @@ -51,24 +55,26 @@ class StockPicking(models.Model): if country_id and user_company_id: # Filter report with Country and Company 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: # Filter report with Country default_report_id = picking._search_default_report( - country_id=country_id) + country_id=country_id + ) if not default_report_id: # Filter report with Company default_report_id = picking._search_default_report( - company_id=user_company_id) + company_id=user_company_id + ) if not default_report_id: # Search for default picking operation report default_report_id = picking._search_default_report() - action_report = report_action_pool.browse( - default_report_id) + action_report = report_action_pool.browse(default_report_id) try: action_report.print_document(picking.id) @@ -79,7 +85,7 @@ class StockPicking(models.Model): @api.multi def write(self, vals): res = super(StockPicking, self).write(vals) - if 'date_done' in vals: + if "date_done" in vals: self._stock_picking_default_auto_print_report() return res @@ -87,8 +93,9 @@ class StockPicking(models.Model): def action_assign(self): res = super(StockPicking, self).action_assign() for picking in self: - if (picking.picking_type_code == 'outgoing' or - picking.location_dest_id.name == 'Output') and \ - picking.state == 'assigned': + if ( + picking.picking_type_code == "outgoing" + or picking.location_dest_id.name == "Output" + ) and picking.state == "assigned": picking._stock_picking_default_auto_print_report() return res diff --git a/stock_picking_auto_print/tests/test_stock_picking_auto_print.py b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py index 04eca89..54f9095 100644 --- a/stock_picking_auto_print/tests/test_stock_picking_auto_print.py +++ b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py @@ -9,45 +9,60 @@ class StockPikcing(TransactionCase): def setUp(self): super(StockPikcing, self).setUp() - self.stock_location = self.env.ref('stock.stock_location_stock') - self.customer_location = self.env.ref('stock.stock_location_customers') - self.scrapped_location = self.env.ref('stock.stock_location_scrapped') + self.stock_location = self.env.ref("stock.stock_location_stock") + self.customer_location = self.env.ref("stock.stock_location_customers") + 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({ - 'name': 'Product A', - 'type': 'product', - 'list_price': 1.0, - 'categ_id': self.env.ref('product.product_category_all').id, - 'uom_id': uom_unit.id - }) + self.product_A = self.env["product.product"].create( + { + "name": "Product A", + "type": "product", + "list_price": 1.0, + "categ_id": self.env.ref("product.product_category_all").id, + "uom_id": uom_unit.id, + } + ) - self.country_us = self.env['res.country'].search( - [('code', 'like', 'US')], limit=1) - self.partner = self.env['res.partner'].create( - {'name': 'BOdedra', 'country_id': self.country_us.id}) + self.country_us = self.env["res.country"].search( + [("code", "like", "US")], limit=1 + ) + self.partner = self.env["res.partner"].create( + {"name": "BOdedra", "country_id": self.country_us.id} + ) - self.so = self.env['sale.order'].create({ - 'partner_id': self.partner.id, - 'partner_invoice_id': self.partner.id, - 'partner_shipping_id': self.partner.id, - 'order_line': [(0, 0, {'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.so = self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "partner_invoice_id": self.partner.id, + "partner_shipping_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + { + "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): """ Auto print when DO is ready or done """ - self.env['stock.quant']._update_available_quantity( - self.product_A, self.stock_location, 2) + self.env["stock.quant"]._update_available_quantity( + self.product_A, self.stock_location, 2 + ) self.so.action_confirm() for picking in self.so.picking_ids: picking.move_lines._do_unreserve() @@ -56,15 +71,17 @@ class StockPikcing(TransactionCase): picking.move_lines._do_unreserve() # Made Delivery Slip report as a default report - deliveryslip_report = self.env['ir.actions.report'].search( - [('report_name', '=', 'stock.report_deliveryslip')]) + deliveryslip_report = self.env["ir.actions.report"].search( + [("report_name", "=", "stock.report_deliveryslip")] + ) - deliveryslip_report.write({'is_default_report': True}) + deliveryslip_report.write({"is_default_report": True}) picking.action_assign() # Remove country ID from Delivery Slip report - deliveryslip_report.write({'country_id': self.country_us.id, - 'company_id': False}) + deliveryslip_report.write( + {"country_id": self.country_us.id, "company_id": False} + ) picking.action_confirm() picking.action_assign() @@ -75,8 +92,8 @@ class StockPikcing(TransactionCase): # Remove company ID from Delivery Slip report deliveryslip_report.write( - {'company_id': self.env.user.company_id.id, - 'country_id': False}) + {"company_id": self.env.user.company_id.id, "country_id": False} + ) picking.action_confirm() picking.action_assign() @@ -84,8 +101,11 @@ class StockPikcing(TransactionCase): picking.move_lines._do_unreserve() 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_assign() picking.action_done() diff --git a/stock_picking_auto_print/views/ir_action_report_view.xml b/stock_picking_auto_print/views/ir_action_report_view.xml index 870124f..a8465a3 100644 --- a/stock_picking_auto_print/views/ir_action_report_view.xml +++ b/stock_picking_auto_print/views/ir_action_report_view.xml @@ -1,15 +1,15 @@ - + country.company.default.report.form ir.actions.report - + - - - + + +