Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] 9.0 saleorder_import_invoice2data and [MIG] sale_commercial_partner / sale_order_import #18

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions base_business_document_import/models/business_document_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,28 @@ def _match_product(self, product_dict, chatter_msg, seller=False):
sinfo = self.env['product.supplierinfo'].search([
('name', '=', seller.id),
('product_code', '=', product_dict['code']),
])
], limit=1)
if (
sinfo and
sinfo[0].product_tmpl_id.product_variant_ids and
len(
sinfo[0].product_tmpl_id.product_variant_ids) == 1
sinfo.product_tmpl_id.product_variant_ids and
len(sinfo.product_tmpl_id.product_variant_ids) == 1
):
return sinfo[0].product_tmpl_id.product_variant_ids[0]
return sinfo.product_tmpl_id.product_variant_ids[0]
if product_dict.get('desc'):
desc = product_dict['desc']
product = ppo.search([('name', '=', desc)], limit=1)
if product:
return product
raise UserError(_(
"Odoo couldn't find any product corresponding to the "
"following information extracted from the business document: "
"following information extracted from the business document:\n"
"EAN13: %s\n"
"Product code: %s\n"
"Product description: %s\n"
"Supplier: %s\n") % (
product_dict.get('ean13'),
product_dict.get('code'),
product_dict.get('desc'),
seller and seller.name or 'None'))

@api.model
Expand Down
4 changes: 2 additions & 2 deletions sale_commercial_partner/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
'name': 'Sale Commercial Partner',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'category': 'Sales Management',
'license': 'AGPL-3',
'summary': "Add stored related field 'Commercial Customer' on sale orders",
Expand All @@ -15,5 +15,5 @@
'views/sale.xml',
'report/sale_report_view.xml',
],
'installable': False,
'installable': True,
}
10 changes: 0 additions & 10 deletions sale_commercial_partner/report/sale_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,3 @@ class SaleReport(models.Model):

commercial_partner_id = fields.Many2one(
'res.partner', string='Commercial Customer', readonly=True)

def _select(self):
sql_str = super(SaleReport, self)._select()
sql_str += ', s.commercial_partner_id as commercial_partner_id'
return sql_str

def _group_by(self):
sql_str = super(SaleReport, self)._group_by()
sql_str += ', s.commercial_partner_id'
return sql_str
6 changes: 0 additions & 6 deletions sale_commercial_partner/report/sale_report_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
-->

<openerp>
<data>


<record id="view_order_product_search" model="ir.ui.view">
<field name="name">commercial.partner.sale.report.search</field>
<field name="model">sale.report</field>
Expand All @@ -20,7 +17,4 @@
</filter>
</field>
</record>


</data>
</openerp>
6 changes: 1 addition & 5 deletions sale_commercial_partner/views/sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
-->

<openerp>
<data>


<record id="view_order_form" model="ir.ui.view">
<field name="name">commercial.partner.sale.order.form</field>
Expand All @@ -24,14 +22,12 @@
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_sales_order_filter"/>
<field name="arch" type="xml">
<filter string="Customer" position="before">
<filter position="before">
<filter name="commercial_partner_groupby"
string="Commercial Customer"
context="{'group_by': 'commercial_partner_id'}"/>
</filter>
</field>
</record>


</data>
</openerp>
4 changes: 2 additions & 2 deletions sale_order_import/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
'name': 'Sale Order Import',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'category': 'Sales Management',
'license': 'AGPL-3',
'summary': 'Import RFQ or sale orders from files',
Expand All @@ -14,5 +14,5 @@
'data': [
'wizard/sale_order_import_view.xml',
],
'installable': False,
'installable': True,
}
81 changes: 32 additions & 49 deletions sale_order_import/wizard/sale_order_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@
logger = logging.getLogger(__name__)


def get_values_for_create(instance):
""" Helper function to get values from object as dict """
return {
f: instance._fields[f].convert_to_write(v)
if not isinstance(instance._fields[f],
fields._RelationalMulti)
else v.ids
for f, v in instance._cache.iteritems()
}


class SaleOrderImport(models.TransientModel):
_name = 'sale.order.import'
_description = 'Sale Order Import from Files'

state = fields.Selection([
('import', 'Import'),
('update', 'Update'),
], string='State', default="import")
], string='State', default="import")
partner_id = fields.Many2one(
'res.partner', string='Customer', domain=[('customer', '=', True)])
csv_import = fields.Boolean(default=False, readonly=True)
Expand All @@ -32,11 +43,11 @@ class SaleOrderImport(models.TransientModel):
doc_type = fields.Selection([
('rfq', 'Request For Quotation'),
('order', 'Sale Order'),
], string='Document Type', readonly=True)
], string='Document Type', readonly=True)
price_source = fields.Selection([
('pricelist', 'Pricelist'),
('order', 'Customer Order'),
], string='Apply Prices From')
], string='Apply Prices From')
# for state = update
commercial_partner_id = fields.Many2one(
'res.partner', string='Customer', readonly=True)
Expand Down Expand Up @@ -77,7 +88,7 @@ def order_file_change(self):
"This file '%s' is not recognised as a CSV, XML nor "
"PDF file. Please check the file and it's "
"extension.") % self.order_filename
}}
}}
else:
self.csv_import = False
self.doc_type = False
Expand All @@ -104,10 +115,10 @@ def parse_pdf_order(self, order_file, detect_doc_type=False):
"""
Get PDF attachments, filter on XML files and call import_order_xml
"""
xml_files_dict = self.get_xml_files_from_pdf(order_file)
bdio = self.env['business.document.import']
xml_files_dict = bdio.get_xml_files_from_pdf(order_file)
if not xml_files_dict:
raise UserError(_(
'There are no embedded XML file in this PDF file.'))
logger.info('There are no embedded XML file in this PDF file.')
for xml_filename, xml_root in xml_files_dict.iteritems():
logger.info('Trying to parse XML file %s', xml_filename)
try:
Expand All @@ -117,39 +128,8 @@ def parse_pdf_order(self, order_file, detect_doc_type=False):
except:
continue
raise UserError(_(
"This type of XML RFQ/order is not supported. Did you install "
"the module to support this XML format?"))

# Format of parsed_order
# {
# 'partner': {
# 'vat': 'FR25499247138',
# 'name': 'Camptocamp',
# 'email': 'luc@camptocamp.com',
# },
# 'ship_to': {
# 'partner': partner_dict,
# 'address': {
# 'country_code': 'FR',
# 'state_code': False,
# 'zip': False,
# }
# 'date': '2016-08-16', # order date
# 'order_ref': 'PO1242', # Customer PO number
# 'currency': {'iso': 'EUR', 'symbol': u'€'},
# 'incoterm': 'EXW',
# 'note': 'order notes of the customer',
# 'chatter_msg': ['msg1', 'msg2']
# 'lines': [{
# 'product': {
# 'code': 'EA7821',
# 'ean13': '2100002000003',
# },
# 'qty': 2.5,
# 'uom': {'unece_code': 'C62'},
# 'price_unit': 12.42, # without taxes
# 'doc_type': 'rfq' or 'order',
# }]
"This type of PDF RFQ/order is not supported. Did you install "
"the module to support this PDF format?"))

@api.model
def _prepare_order(self, parsed_order, price_source):
Expand All @@ -172,7 +152,7 @@ def _prepare_order(self, parsed_order, price_source):
('client_order_ref', '=', parsed_order['order_ref']),
('partner_id', '=', partner.id),
('state', '!=', 'cancel'),
])
])
if existing_orders:
raise UserError(_(
"An order of customer '%s' with reference '%s' "
Expand All @@ -181,14 +161,17 @@ def _prepare_order(self, parsed_order, price_source):
parsed_order['order_ref'],
existing_orders[0].name,
existing_orders[0].state))
partner_change_res = soo.onchange_partner_id(partner.id)
assert 'value' in partner_change_res, 'Error in partner change'
values = {'partner_id': partner.id}
fake_so = soo.new(values)
fake_so.onchange_partner_id()

partner_change_res = get_values_for_create(fake_so)
so_vals = {
'partner_id': partner.id,
'client_order_ref': parsed_order.get('order_ref'),
'order_line': []
}
so_vals.update(partner_change_res['value'])
}
so_vals.update(partner_change_res)
if parsed_order.get('ship_to'):
shipping_partner = bdio._match_shipping_partner(
parsed_order['ship_to'], partner, parsed_order['chatter_msg'])
Expand Down Expand Up @@ -284,7 +267,7 @@ def import_order_button(self):
'state': 'update',
'sale_id': default_sale_id,
'doc_type': parsed_order.get('doc_type'),
})
})
action = self.env['ir.actions.act_window'].for_xml_id(
'sale_order_import', 'sale_order_import_action')
action['res_id'] = self.id
Expand Down Expand Up @@ -314,7 +297,7 @@ def create_order_return_action(self, parsed_order):
'views': False,
'view_id': False,
'res_id': order.id,
})
})
return action

@api.model
Expand Down Expand Up @@ -367,7 +350,7 @@ def update_order_lines(self, parsed_order, order):
'uom': oline.product_uom,
'line': oline,
'price_unit': price_unit,
})
})
compare_res = bdio.compare_lines(
existing_lines, parsed_order['lines'], chatter,
qty_precision=qty_prec, seller=False)
Expand Down Expand Up @@ -463,5 +446,5 @@ def update_order_button(self):
'views': False,
'view_id': False,
'res_id': order.id,
})
})
return action
4 changes: 1 addition & 3 deletions sale_order_import/wizard/sale_order_import_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
-->

<openerp>
<data>

<record id="sale_order_import_form" model="ir.ui.view">
<field name="name">sale.order.import.form</field>
Expand All @@ -21,7 +20,7 @@
<ol>
<li>If it is a CSV file, you will have to manually select the customer. The CSV file should have 2 columns: the product reference or EAN13 (1st col) and then the product quantity (2nd col). It shouldn't have any header line and use semi-colon as field separator. The quantity shouldn't use any thousand separator ; if it is a decimal value, it should use dot as the decimal separator.</li>
<li>If it is an XML file, Odoo will parse it if the module that adds support for this XML format is installed. For the <a href="http://ubl.xml.org/" target="_blank">Universal Business Language</a> format (UBL), you should install the module <em>sale_order_import_ubl</em>.</li>
<li>If it is a PDF file, Odoo will try to find an XML file in the attachments of the PDF file and then use this XML file to create the quotation.</li>
<li>If it is a PDF file, Odoo will first try to parse this document according to the invoice2data templates that are loaded. If that fails, it will try to find an XML file in the attachments of the PDF file and then use this XML file to create the quotation.</li>
</ol>
</div>
</group>
Expand Down Expand Up @@ -74,5 +73,4 @@
parent="base.menu_sales"
action="sale_order_import_action" sequence="25"/>

</data>
</openerp>
Loading