Skip to content

Commit 0aa5a11

Browse files
C2C-479: Fix invoice endpoint (#15)
1 parent 2165050 commit 0aa5a11

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

api/src/main/java/org/openmrs/module/erp/api/impl/odoo/OdooInvoiceServiceImpl.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ public class OdooInvoiceServiceImpl implements ErpInvoiceService {
2222

2323
private static final String INVOICE_MODEL = "account.move";
2424

25-
private ArrayList<String> invoiceDefaultAttributes = new ArrayList<String>(Arrays.asList("name", "amount_total", "state",
26-
"pricelist_id", "payment_term_id", "invoice_status", "origin", "create_date", "currency_id"));
25+
private ArrayList<String> invoiceDefaultAttributes = new ArrayList<String>(
26+
Arrays.asList("id", "name", "date", "state", "invoice_date", "invoice_date_due", "payment_state", "amount_total",
27+
"amount_residual", "currency_id", "partner_id", "invoice_origin", "create_date"));
28+
29+
private ArrayList<String> invoiceLineAttributes = new ArrayList<String>(Arrays.asList("id", "name", "quantity",
30+
"product_uom_id", "move_id", "product_id", "price_unit", "price_subtotal", "price_total", "display_type"));
2731

2832
@Autowired
2933
private OdooClient odooClient;
@@ -57,7 +61,12 @@ public Map<String, Object> getInvoiceById(String invoiceId) {
5761
try {
5862

5963
Object[] records = (Object[]) odooClient.execute("read", INVOICE_MODEL,
60-
Collections.singletonList(Integer.parseInt(invoiceId)), null);
64+
Collections.singletonList(Integer.parseInt(invoiceId)), new HashMap() {
65+
66+
{
67+
put("fields", invoiceDefaultAttributes);
68+
}
69+
});
6170

6271
if ((records != null) && (records.length > 0)) {
6372
Map record = (Map) records[0];
@@ -95,7 +104,7 @@ public List<Map<String, Object>> getInvoicesByFilters(List<Filter> filters) {
95104
filterCollection.add(asList(filter.getFieldName(), filter.getComparison(), filter.getValue()));
96105
}
97106

98-
ArrayList<String> fields = odooClient.getDomainFields(INVOICE_MODEL);
107+
ArrayList<String> fields = invoiceDefaultAttributes;
99108
Object[] records = (Object[]) odooClient.execute("search_read", INVOICE_MODEL, filterCollection, new HashMap() {
100109

101110
{
@@ -144,7 +153,7 @@ private List<Map<String, Object>> getInvoiceLinesByInvoiceId(String invoiceId) {
144153

145154
filterCollection.add(condition);
146155

147-
ArrayList<String> fields = odooClient.getDomainFields("account.move.line");
156+
ArrayList<String> fields = invoiceLineAttributes;
148157
Object[] records = (Object[]) odooClient.execute("search_read", "account.move.line", filterCollection,
149158
new HashMap() {
150159

@@ -163,6 +172,7 @@ private List<Map<String, Object>> getInvoiceLinesByInvoiceId(String invoiceId) {
163172
Object value = rec.get(field);
164173
result.put(field, value);
165174
}
175+
result.put("exclude_from_invoice_tab", isExcludedFromInvoiceTab(result.get("display_type")));
166176
response.add(result);
167177
});
168178
}
@@ -172,4 +182,11 @@ private List<Map<String, Object>> getInvoiceLinesByInvoiceId(String invoiceId) {
172182
}
173183
return response;
174184
}
185+
186+
private boolean isExcludedFromInvoiceTab(Object displayType) {
187+
if (displayType == null || Boolean.FALSE.equals(displayType)) {
188+
return false;
189+
}
190+
return !"product".equals(displayType);
191+
}
175192
}

api/src/main/java/org/openmrs/module/erp/api/utils/ErpPropertiesFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public static File getFile() {
2525
if (file.exists()) {
2626
return file;
2727
}
28-
LogFactory.getLog(ErpPropertiesFile.class).warn("Could not find erp.properties file in directory: " + file.getParent() + ". Failing over to location /etc/properties/.");
28+
LogFactory.getLog(ErpPropertiesFile.class).warn("Could not find erp.properties file in directory: "
29+
+ file.getParent() + ". Failing over to location /etc/properties/.");
2930
return new File("/etc/properties/", fileName);
3031
}
3132

omod/src/main/java/org/openmrs/module/erp/web/controller/ErpInvoiceController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ErpInvoiceController {
2323
@Autowired
2424
@Qualifier(ErpConstants.COMPONENT_ODOO_INVOICE_SERVICE)
2525
protected ErpInvoiceService erpInvoiceService;
26-
26+
2727
@RequestMapping(method = RequestMethod.POST)
2828
@ResponseBody
2929
public Object getInvoicesByFilters(@RequestBody String jsonString,

omod/src/main/java/org/openmrs/module/erp/web/controller/ErpPartnerController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ErpPartnerController extends BaseRestController {
2929
@ResponseBody
3030
public Object getErpPartnersByFilters(@RequestBody String jsonString,
3131
@RequestParam(value = "rep", defaultValue = "default") String rep) {
32-
32+
3333
RecordRepresentation recordRepresentation = new RecordRepresentation(erpPartnerService.defaultModelAttributes());
3434

3535
ArrayList<Filter> filtersArray = new ArrayList<>();
@@ -62,7 +62,7 @@ public Object getErpPartnersByFilters(@RequestBody String jsonString,
6262
@ResponseBody
6363
public Object getErpPartnerById(@PathVariable("id") String id,
6464
@RequestParam(value = "rep", defaultValue = "default") String rep) {
65-
65+
6666
return new RecordRepresentation(erpPartnerService.defaultModelAttributes())
6767
.getRepresentedRecord(erpPartnerService.getErpPartnerById(id), rep);
6868
}

0 commit comments

Comments
 (0)