| 1 |
from odoo import _, api, models, Command |
| 2 |
|
| 3 |
|
| 4 |
class PurchaseOrder(models.Model): |
| 5 |
_inherit = "purchase.order" |
| 6 |
|
| 7 |
def _get_edi_builders(self): |
| 8 |
return super()._get_edi_builders() + [self.env['purchase.edi.xml.ubl_bis3']] |
| 9 |
|
| 10 |
def _get_import_file_type(self, file_data): |
| 11 |
""" Identify UBL files. """ |
| 12 |
# EXTENDS 'account' |
| 13 |
if (tree := file_data['xml_tree']) is not None: |
| 14 |
customization_id = tree.find('{*}CustomizationID') |
| 15 |
if customization_id is not None: |
| 16 |
if customization_id.text == 'urn:fdc:peppol.eu:poacc:trns:order:3': |
| 17 |
return 'purchase.edi.xml.ubl_bis3' |
| 18 |
return super()._get_import_file_type(file_data) |
| 19 |
|
| 20 |
def _get_edi_decoder(self, file_data, new=False): |
| 21 |
""" Override of purchase to add edi decoder for xml files. |
| 22 |
|
| 23 |
:param dict file_data: File data to decode. |
| 24 |
""" |
| 25 |
if file_data['import_file_type'] == 'purchase.edi.xml.ubl_bis3': |
| 26 |
return { |
| 27 |
'priority': 20, |
| 28 |
'decoder': self.env['purchase.edi.xml.ubl_bis3']._import_order_ubl, |
| 29 |
} |
| 30 |
return super()._get_edi_decoder(file_data, new) |
| 31 |
|
| 32 |
def _create_activity_set_details(self, body): |
| 33 |
""" Create activity on purchase order to set details. |
| 34 |
:return: None. |
| 35 |
""" |
| 36 |
activity_message = _("Some information could not be imported:") |
| 37 |
activity_message += body |
| 38 |
self.activity_schedule( |
| 39 |
'mail.mail_activity_data_todo', |
| 40 |
user_id=self.env.user.id, |
| 41 |
note=activity_message, |
| 42 |
) |
| 43 |
|
| 44 |
@api.model |
| 45 |
def _get_line_vals_list(self, lines_vals): |
| 46 |
""" Get purchases order line values list. |
| 47 |
:param list line_vals: List of values [name, qty, price, tax]. |
| 48 |
:return: List of dict values. |
| 49 |
""" |
| 50 |
|
| 51 |
return [{ |
| 52 |
'sequence': 0, # be sure to put these lines above the 'real' order lines |
| 53 |
'name': name, |
| 54 |
'product_qty': quantity, |
| 55 |
'price_unit': price_unit, |
| 56 |
'taxes_id': [Command.set(tax_ids)], |
| 57 |
} for name, quantity, price_unit, tax_ids in lines_vals] |